runAppAsync<T extends Object> function
Future<ComponentRef<T> >
runAppAsync<T extends Object>(
- ComponentFactory<
T> componentFactory, { - required Future<
void> beforeComponentCreated(), - InjectorFactory createInjector = _identityInjector,
Asynchronous alternative to runApp, supporting beforeComponentCreated
.
The provided callback (beforeComponentCreated
) is invoked before
creating the root component, with a handle to the root injector. The user
must return a Future
- it will be await
-ed before creating the root
component.
See runApp for additional details.
Implementation
Future<ComponentRef<T>> runAppAsync<T extends Object>(
ComponentFactory<T> componentFactory, {
required Future<void> Function(Injector) beforeComponentCreated,
InjectorFactory createInjector = _identityInjector,
}) {
final injector = appInjector(createInjector);
final appRef = injector.provideType<ApplicationRef>(ApplicationRef);
final ngZone = injector.provideType<NgZone>(NgZone);
return ngZone.run(() {
final future = beforeComponentCreated(injector);
return future.then((_) => appRef.bootstrap(componentFactory));
});
}