Future activate(ComponentInstruction nextInstruction)

Called by the Router to instantiate a new component during the commit phase of a navigation. This method in turn is responsible for calling the routerOnActivate hook of its child.

Source

Future<dynamic> activate(ComponentInstruction nextInstruction) {
  var previousInstruction = this._currentInstruction;
  this._currentInstruction = nextInstruction;
  var componentType = nextInstruction.componentType;
  var childRouter = this._parentRouter.childRouter(componentType);
  var providers = new Map<dynamic, dynamic>();
  providers[RouteData] = nextInstruction.routeData;
  providers[RouteParams] = new RouteParams(nextInstruction.params);
  providers[router_mod.Router] = childRouter;
  var injector =
      new MapInjector(this._viewContainerRef.parentInjector, providers);
  Future<ComponentFactory> componentFactoryPromise;
  if (componentType is ComponentFactory) {
    componentFactoryPromise = new Future.value(componentType);
  } else {
    componentFactoryPromise = this._loader.resolveComponent(componentType);
  }
  this._componentRef = componentFactoryPromise.then((componentFactory) =>
      this._viewContainerRef.createComponent(componentFactory, 0, injector));
  return this._componentRef.then((componentRef) {
    this.activateEvents.emit(componentRef.instance);
    if (hasLifecycleHook(hook_mod.routerOnActivate, componentRef.instance)) {
      return ((componentRef.instance as OnActivate))
          .routerOnActivate(nextInstruction, previousInstruction);
    } else {
      return componentRef;
    }
  });
}