在Angular2路由器生命周期挂钩 [英] Life cycle hooks in Angular2 router

查看:176
本文介绍了在Angular2路由器生命周期挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有问题与angular2路由器添加的生命周期挂钩。这将是有益的,如果任何人都可以共享code添加的生命周期挂钩的Angular2路由器。

Having issue with adding the life cycle hooks in angular2 router. It would be helpful if anyone can share the code to add the Life cycle hooks in Angular2 router.

推荐答案

我如何添加可激活钩子。埃里克感谢您的帮助。
不像其他的生命周期挂钩CanActivate被添加作为注解。

I got how to add the "Can Activate" hook. Thanks Erik for your help. Unlike the other lifecycle hooks "CanActivate" is added as an annotation.

import {CanActivate} from 'angular2/router';
@Component({
    selector:'help'
})
@View({
    templateUrl:'../../templates/help/help.html',
    directives:[HelpHeader, HelpContent]
})
@CanActivate(() => true)
export class Help{}

这篇关于在Angular2路由器生命周期挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆