Vinz and Tonz
Vinz and Tonz

Reputation: 3587

Life cycle hooks in Angular2 router

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.

Upvotes: 4

Views: 7522

Answers (1)

Vinz and Tonz
Vinz and Tonz

Reputation: 3587

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{}

Upvotes: 6

Related Questions