I'm having this issue and I can't really figure out how to solve this. I have this component:
(function () {
'use strict';
// Usage:
//
// Creates:
//
myApp
.component('navbar', {
//template:'htmlTemplate',
templateUrl: 'app/components/navbar/navbar.partial.html',
controller: ControllerController,
bindings: {
progress: '<'
},
});
ControllerController.$inject = ['$scope','$rootScope','changeState'];
function ControllerController($scope,$rootScope,changeState) {
var $ctrl = this;
$scope.$on('state-changed',function(event,args){
console.log(args);
});
$ctrl.$onInit = function () { };
$ctrl.$onChanges = function (changesObj) { };
$ctrl.$onDestory = function () { };
}
})();
The event 'state-changed' is triggered on $transitions.onSuccess (ui-router 1.0 Beta). Here the code:
var myApp = angular.module('myApp', ['ui.router']);
myApp.controller('appCtrl', ['$scope', '$state', 'formDataService', '$timeout', '$transitions','changeState','$transitions',
function ($scope, $state, formDataService, $timeout, $transitions,changeState,$transitions) {
changeState.go('1');
$scope.stateByFar = 1;
$scope.currentState = function(){
return $state.current.name;
};
$scope.updateStateByFar = function(){
if (parseInt($scope.currentState())>$scope.stateByFar)
$scope.stateByFar=parseInt($scope.currentState());
};
$transitions.onSuccess({to: '*'}, function(){
$scope.updateStateByFar();
console.log($scope.stateByFar);
$scope.$broadcast('state-changed',{currentState: $scope.currentState(),
stateByFar : $scope.stateByFar});
}
);
}]);
[EDIT] The broadcast actually works. can't broadcast on the first state.go tho. when the main module runs, the first instruction is : $state.go('1'); and I can't detect this first state.go. Further state.go are listened.