fizz buzz
fizz buzz

Reputation: 13

Angular ui-router: onEnter function is not firing when new state is entered

I am trying to learn ui-router, and angular, doing so by building the usual todo app.

My stateprovider code looks like so:

app.config(['$httpProvider', '$stateProvider', '$urlRouterProvider', function ($httpProvider, $stateProvider, $urlRouterProvider) {
    'use strict';
    $stateProvider
        .state('alltasks', {
            url: '',
            templateUrl: '/templates/tpl.alltasks.html',
            controller: 'TasksCtrl'
        })
        .state('addtask', {
            url: '/add',
            template: 'test',
            onEnter: function () {
                console.log('entered projects add state');
            }
        });
}]);

I expected the console.log to fire when I enter the addtask state, but it does not.

Upvotes: 1

Views: 481

Answers (1)

GPicazo
GPicazo

Reputation: 6676

There isn't anything wrong with the code you posted. Here is a working plunkr that you can compare to: plnkr.co/edit/GMfwVYXIXM2p7kkQU1Xj?p=preview . In particular, you may want to check your library versions and that you are actually linking/navigating to the addtask state.

Upvotes: 1

Related Questions