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.
bootstrapApplication(rootComponent: Type<unknown>, options?: ApplicationConfig): Promise<ApplicationRef>
Parameters
rootComponent
|
Type<unknown> |
A reference to a standalone component that should be rendered. |
options
|
ApplicationConfig |
Extra configuration for the bootstrap operation, see Optional. Default is |
Returns
Promise<ApplicationRef>
: A promise that returns an ApplicationRef
instance once resolved.
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()]});