angular-docs-cn/modules/angular2/src/router/route_lifecycle_reflector.ts

21 lines
658 B
TypeScript
Raw Normal View History

import {Type, isPresent} from 'angular2/src/facade/lang';
import {RouteLifecycleHook, CanActivate} from './lifecycle_annotations_impl';
2015-08-20 14:28:25 -07:00
import {reflector} from 'angular2/src/core/reflection/reflection';
export function hasLifecycleHook(e: RouteLifecycleHook, type): boolean {
if (!(type instanceof Type)) return false;
return e.name in(<any>type).prototype;
}
export function getCanActivateHook(type): Function {
var annotations = reflector.annotations(type);
for (let i = 0; i < annotations.length; i += 1) {
let annotation = annotations[i];
if (annotation instanceof CanActivate) {
return annotation.fn;
}
}
return null;
}