Angular 2: Inject a dependency into @CanActivate?

后端 未结 5 1200
心在旅途
心在旅途 2021-01-02 06:55

In Angular 2, you can specify a @CanActivate annotation for a component where you can determine if the component should be activated or not. The reason it\'s no

5条回答
  •  星月不相逢
    2021-01-02 07:21

    I don't know if its the best way, but these guys do it by extending and using its own and override the CanActivate method:

    https://auth0.com/blog/2015/05/14/creating-your-first-real-world-angular-2-app-from-authentication-to-calling-an-api-and-everything-in-between/

    Also you could use routerOnActivate instead.

    https://angular.io/docs/js/latest/api/router/OnActivate-interface.html I hope this helps.

提交回复
热议问题