bootstrap<T extends Object> method
Bootstrap a new component at the root level of the application.
When bootstrapping a new root component into an application, Angular mounts the specified application component onto DOM elements identified by the component's selector and kicks off automatic change detection to finish initializing the component.
Implementation
ComponentRef<T> bootstrap<T extends Object>(
ComponentFactory<T> componentFactory,
) {
return unsafeCast(run(() {
final component = componentFactory.create(_injector);
final existing = querySelector(componentFactory.selector);
Element? replacement;
if (existing != null) {
final newElement = component.location;
// For app shards using bootstrapStatic, transfer element id
// from original node to allow hosting applications to locate loaded
// application root.
if (newElement.id.isEmpty) {
newElement.id = existing.id;
}
replacement = newElement;
existing.replaceWith(replacement);
} else {
document.body!.append(component.location);
}
final injector = component.injector;
final testability = injector.provideTypeOptional<Testability>(
Testability,
);
if (testability != null) {
final registry = _injector.provideType<TestabilityRegistry>(
TestabilityRegistry,
);
registry.registerApplication(component.location, testability);
}
_loadedRootComponent(component, replacement);
return component;
}));
}