runApp<T> function

ComponentRef<T> runApp<T>(
  1. ComponentFactory<T> componentFactory,
  2. {InjectorFactory createInjector = _identityInjector}

Starts a new AngularDart application with componentFactory as the root.

// Assume this file is "main.dart".
import 'package:angular/angular.dart';
import 'main.template.dart' as ng;

  selector: 'hello-world',
  template: '',
class HelloWorld {}

void main() {

See ComponentFactory for documentation on how to find an instance of a ComponentFactory<T> given a class T annotated with @Component. An HTML tag matching the selector defined in Component.selector will be upgraded to use AngularDart to manage that element (and its children). If there is no matching element, a new tag will be appended to the <body>.

Optionally may supply a createInjector function in order to provide services to the root of the application:

// Assume this file is "main.dart". import 'package:angular/angular.dart'; import 'main.template.dart' as ng;

@Component( selector: 'hello-world', template: '', ) class HelloWorld { HelloWorld(HelloService service) { service.sayHello(); } }

class HelloService { void sayHello() { print('Hello World!'); } }

void main() { runApp(ng.HelloWorldNgFactory, createInjector: helloInjector); }

@GenerateInjector(const const ClassProvider(HelloService), ) final InjectorFactory helloInjector = ng.helloInjector$Injector;

See [InjectorFactory] for more examples.

Returns a [ComponentRef] with the created root component instance within the
context of a new [ApplicationRef], with change detection and other framework
internals setup.


ComponentRef<T> runApp<T>(
  ComponentFactory<T> componentFactory, {
  InjectorFactory createInjector = _identityInjector,
}) {
  if (isDevMode && componentFactory == null) {
    throw ArgumentError.notNull('componentFactory');
  final injector = appInjector(createInjector);
  final appRef = injector.provideType<ApplicationRef>(ApplicationRef);
  return appRef.bootstrap(componentFactory);