runAppAsync<T> function

Future<ComponentRef<T>> runAppAsync <T>(ComponentFactory<T> componentFactory, { @required Future<void> beforeComponentCreated(Injector), 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.


Future<ComponentRef<T>> runAppAsync<T>(
  ComponentFactory<T> componentFactory, {
  @required Future<void> Function(Injector) beforeComponentCreated,
  InjectorFactory createInjector = _identityInjector,
}) {
  if (isDevMode) {
    if (componentFactory == null) {
      throw ArgumentError.notNull('componentFactory');
    if (beforeComponentCreated == null) {
      throw ArgumentError.notNull('beforeComponentCreated');
  final injector = appInjector(createInjector);
  final appRef = injector.provideType<ApplicationRef>(ApplicationRef);
  final ngZone = injector.provideType<NgZone>(NgZone);
  return {
    final Future<void> future = beforeComponentCreated(injector);
    assert(future != null, 'beforeComponentCreated must return a Future');
    return future.then((_) => appRef.bootstrap(componentFactory));