0

Seems that OnActivate is removed in angular 2 rc 6, what is the alternative for this.

I need to have a method which is called when all canActivate methods passed for a particular route changes, this method also should have the capability to accept the promise to hold the navigation.

Gherbi Hicham
  • 2,416
  • 4
  • 26
  • 41
sathishkumar
  • 1,780
  • 4
  • 20
  • 31

1 Answers1

0

These are replaced by guards

class UserToken {}
class Permissions {
  canActivate(user: UserToken, id: string): boolean {
    return true;
  }
}
@Injectable()
class CanActivateTeam implements CanActivate {
  constructor(private permissions: Permissions, private currentUser: UserToken) {}
  canActivate(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ): Observable<boolean>|Promise<boolean>|boolean {
    return this.permissions.canActivate(this.currentUser, route.params.id);
  }
}
@NgModule({
  imports: [
    RouterModule.forRoot([
      {
        path: 'team/:id',
        component: TeamCmp,
        canActivate: [CanActivateTeam]
      }
    ])
  ],
  providers: [CanActivateTeam, UserToken, Permissions]
})
class AppModule {}
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567