runAppAsync<T extends Object> function

Future<ComponentRef<T>> runAppAsync<T extends Object>(
  1. ComponentFactory<T> componentFactory, {
  2. required Future<void> beforeComponentCreated(
    1. Injector
    ),
  3. 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));
  });
}