runApp<T extends Object> function

ComponentRef<T> runApp<T extends Object>(
  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:ngdart/angular.dart';
import 'main.template.dart' as ng;

@Component(
  selector: 'hello-world',
  template: '',
)
class HelloWorld {}

void main() {
  runApp(ng.HelloWorldNgFactory);
}

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:ngdart/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.

Implementation

ComponentRef<T> runApp<T extends Object>(
  ComponentFactory<T> componentFactory, {
  InjectorFactory createInjector = _identityInjector,
}) {
  final injector = appInjector(createInjector);
  final appRef = injector.provideType<ApplicationRef>(ApplicationRef);
  return appRef.bootstrap(componentFactory);
}