angular / router

The Angular 1 Component Router
MIT License
665 stars 135 forks source link

Lifecyle Hooks don't work with templateUrl #389

Open amritk opened 8 years ago

amritk commented 8 years ago

If you are using a templateUrl, your lifecycle hooks don't get triggered. This works:

angular.module('app.about', []).directive('about', AboutRoute);

function AboutRoute() {
  return {
    template: 'About {{ vm.name }}',
    controller: AboutController,
    controllerAs: 'vm'
  };
}

function AboutController() {
    console.log('controller loaded');
}

AboutController.prototype.$routerOnActivate = function(toRoute, fromRoute) {
    console.log('hook triggered');
    this.name = toRoute.params.name;
}

While this doesn't:

angular.module('app.about', []).directive('about', AboutRoute);

function AboutRoute() {
  return {
    templateUrl: 'about.html',
    controller: AboutController,
    controllerAs: 'vm'
  };
}

function AboutController() {
    console.log('controller loaded');
}

AboutController.prototype.$routerOnActivate = function(toRoute, fromRoute) {
    console.log('hook triggered');
    this.name = toRoute.params.name;
}