2015-04-17 09:59:56 -07:00
|
|
|
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
|
2015-05-03 20:25:04 -07:00
|
|
|
import {isBlank} from 'angular2/src/facade/lang';
|
2015-04-17 09:59:56 -07:00
|
|
|
|
2015-04-30 13:38:40 -07:00
|
|
|
import {Directive} from 'angular2/src/core/annotations_impl/annotations';
|
2015-05-03 20:25:04 -07:00
|
|
|
import {Attribute} from 'angular2/src/core/annotations_impl/di';
|
2015-04-17 09:59:56 -07:00
|
|
|
import {Compiler, ViewContainerRef} from 'angular2/core';
|
|
|
|
import {Injector, bind} from 'angular2/di';
|
|
|
|
|
|
|
|
import * as routerMod from './router';
|
|
|
|
import {Instruction, RouteParams} from './instruction'
|
|
|
|
|
2015-04-30 13:38:40 -07:00
|
|
|
@Directive({
|
2015-04-17 09:59:56 -07:00
|
|
|
selector: 'router-outlet'
|
|
|
|
})
|
|
|
|
export class RouterOutlet {
|
|
|
|
_compiler:Compiler;
|
|
|
|
_injector:Injector;
|
|
|
|
_router:routerMod.Router;
|
|
|
|
_viewContainer:ViewContainerRef;
|
|
|
|
|
2015-05-06 18:30:37 -07:00
|
|
|
constructor(viewContainer:ViewContainerRef, compiler:Compiler, router:routerMod.Router, injector:Injector, @Attribute('name') nameAttr:String) {
|
2015-05-03 20:25:04 -07:00
|
|
|
if (isBlank(nameAttr)) {
|
|
|
|
nameAttr = 'default';
|
|
|
|
}
|
2015-04-17 09:59:56 -07:00
|
|
|
this._router = router;
|
|
|
|
this._viewContainer = viewContainer;
|
|
|
|
this._compiler = compiler;
|
|
|
|
this._injector = injector;
|
2015-05-03 20:25:04 -07:00
|
|
|
this._router.registerOutlet(this, nameAttr);
|
2015-04-17 09:59:56 -07:00
|
|
|
}
|
|
|
|
|
2015-05-14 15:24:35 +02:00
|
|
|
activate(instruction:Instruction): Promise {
|
2015-04-17 09:59:56 -07:00
|
|
|
return this._compiler.compileInHost(instruction.component).then((pv) => {
|
|
|
|
var outletInjector = this._injector.resolveAndCreateChild([
|
|
|
|
bind(RouteParams).toValue(new RouteParams(instruction.params)),
|
|
|
|
bind(routerMod.Router).toValue(instruction.router)
|
|
|
|
]);
|
|
|
|
|
|
|
|
this._viewContainer.clear();
|
2015-05-08 17:58:08 -07:00
|
|
|
this._viewContainer.create(pv, 0, null, outletInjector);
|
2015-04-17 09:59:56 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-05-14 15:24:35 +02:00
|
|
|
canActivate(instruction:Instruction): Promise<boolean> {
|
2015-04-17 09:59:56 -07:00
|
|
|
return PromiseWrapper.resolve(true);
|
|
|
|
}
|
|
|
|
|
2015-05-14 15:24:35 +02:00
|
|
|
canDeactivate(instruction:Instruction): Promise<boolean> {
|
2015-04-17 09:59:56 -07:00
|
|
|
return PromiseWrapper.resolve(true);
|
|
|
|
}
|
|
|
|
}
|