ui-router 0.2.11 / AngularJS 1.3.0
I struggle to understand why my $stateChangeSuccess event handler in BarCtrl is not triggered on #/foo/bar. It is triggered on #/bar.
#/foo/bar -> Console: foo
#/bar -> Console: bar
What I'm trying to achieve is that on #/foo/bar first FooCtrl's handler is triggered and then BarCtrl's:
foo
bar
My code:
var app = angular.module('foobar', ['restangular', 'ui.bootstrap', 'ui.router'])
app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider.state('root', {
url: "/",
template: '<div ui-view></div>'
})
.state('foo', {
abstract: true,
url: "/foo",
controller: 'FooCtrl',
})
.state('foo.bar', {
url: "/bar",
controller: 'BarCtrl',
})
.state('bar', {
url: "/bar",
controller: 'BarCtrl',
});
})
app.controller('FooCtrl', function($scope) {
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){
console.log("foo");
});
});
app.controller('BarCtrl', function($scope) {
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){
console.log('bar')
});
});