feat: add RouterOutlet

This commit is contained in:
vsavkin 2016-05-24 13:21:38 -07:00
parent 1be9ea681b
commit aad7010952
1 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import {Directive, ViewContainerRef, Attribute, ComponentRef, ComponentFactory, ResolvedReflectiveProvider, ReflectiveInjector} from '@angular/core';
import {RouterOutletMap} from '../router_outlet_map';
import {PRIMARY_OUTLET} from '../router_state';
@Directive({selector: 'router-outlet'})
export class RouterOutlet {
private activated:ComponentRef<any>|null;
public outletMap:RouterOutletMap;
constructor(parentOutletMap:RouterOutletMap, private location:ViewContainerRef,
@Attribute('name') name:string) {
parentOutletMap.registerOutlet(name ? name : PRIMARY_OUTLET, this);
}
get isActivated(): boolean { return !!this.activated; }
deactivate(): void {
if (this.activated) {
this.activated.destroy();
this.activated = null;
}
}
activate(factory: ComponentFactory<any>, providers: ResolvedReflectiveProvider[],
outletMap: RouterOutletMap): void {
this.outletMap = outletMap;
let inj = ReflectiveInjector.fromResolvedProviders(providers, this.location.parentInjector);
this.activated = this.location.createComponent(factory, this.location.length, inj, []);
}
}