bootstrapApplication
Bootstraps an instance of an Angular application and renders a standalone component as the application's root component. More information about standalone components can be found in this guide.
API
function bootstrapApplication(
rootComponent: Type<unknown>,
options?: ApplicationConfig | undefined,
context?: BootstrapContext | undefined,
): Promise<ApplicationRef>;bootstrapApplication
Promise<ApplicationRef>Bootstraps an instance of an Angular application and renders a standalone component as the application's root component. More information about standalone components can be found in this guide.
ApplicationConfig | undefinedExtra configuration for the bootstrap operation, see ApplicationConfig for
additional info.
BootstrapContext | undefinedOptional context object that can be used to provide a pre-existing platform injector. This is useful for advanced use-cases, for example, server-side rendering, where the platform is created for each request.
Promise<ApplicationRef>Usage Notes
The root component passed into this function must be a standalone one (should have the
standalone: true flag in the @Component decorator config).
@Component({ standalone: true, template: 'Hello world!'})class RootComponent {}const appRef: ApplicationRef = await bootstrapApplication(RootComponent);
You can add the list of providers that should be available in the application injector by
specifying the providers field in an object passed as the second argument:
await bootstrapApplication(RootComponent, { providers: [ {provide: BACKEND_URL, useValue: 'https://yourdomain.com/api'} ]});
The importProvidersFrom helper method can be used to collect all providers from any
existing NgModule (and transitively from all NgModules that it imports):
await bootstrapApplication(RootComponent, { providers: [ importProvidersFrom(SomeNgModule) ]});
Note: the bootstrapApplication method doesn't include Testability by
default. You can add Testability by getting the list of necessary
providers using provideProtractorTestingSupport() function and adding them into the providers
array, for example:
import {provideProtractorTestingSupport} from '@angular/platform-browser';await bootstrapApplication(RootComponent, {providers: [provideProtractorTestingSupport()]});