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.
Asked
Active
Viewed 7,428 times
4
-
What version are you using? What have you tried so far? – Eric Martinez Sep 11 '15 at 23:25
-
I'm not sure if I understand your question. Lifecycle in a router component works like in any component. Just move to alpha37 and change to implementation of Lifecycle Hooks. – Eric Martinez Sep 12 '15 at 16:56
-
All lifecycle hooks are working except "CanActivate". Is their any difference in implementing "CanActivate" ? – Vinz and Tonz Sep 12 '15 at 19:34
-
2Sorry, when you said lifecycle hooks I was thinking of `onInit`, `doCheck`, etc. I've found [this issue](https://github.com/angular/angular/issues/4112), see the plnkr from @brandonroberts, it shows how to use it. – Eric Martinez Sep 12 '15 at 19:57
1 Answers
6
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{}

DenisKolodin
- 13,501
- 3
- 62
- 65

Vinz and Tonz
- 3,487
- 5
- 21
- 32