runAppLegacy<T> function

ComponentRef<T> runAppLegacy <T>(Type componentType, { List<Object> createInjectorFromProviders: const [], void initReflector() })

Starts a new AngularDart application with componentType as the root.

This method is soft deprecated, and runApp is preferred as soon as initReflector is no longer needed in your application. Specifically, using this method enables the use of the following deprecated APIs:

  • ReflectiveInjector
  • SlowComponentLoader

... if neither your app nor your dependencies requires these APIs, it is recommended to switch to runApp instead, which has significant code-size and startup time benefits.

Implementation

ComponentRef<T> runAppLegacy<T>(
  Type componentType, {
  List<Object> createInjectorFromProviders = const [],
  void Function() initReflector,
}) {
  assert(T == dynamic || T == componentType, 'Expected $componentType == $T');
  if (initReflector != null) {
    initReflector();
  }
  if (isDevMode) {
    if (componentType == null) {
      throw ArgumentError.notNull('componentType');
    }
    if (initReflector == null) {
      try {
        typeToFactory(componentType);
      } on StateError catch (_) {
        throw ArgumentError(
          'Could not bootstrap $componentType: provide "initReflector".',
        );
      }
    }
  }
  return runApp(
    unsafeCast(typeToFactory(componentType)),
    createInjector: ([parent]) {
      return ReflectiveInjector.resolveAndCreate(
        [
          SlowComponentLoader,
          createInjectorFromProviders,
        ],
        unsafeCast(parent),
      );
    },
  );
}