I am using $scope.$emit in my ListController to trigger a $rootScope.$on event in the MainController(angular 1.3):
(function () {
'use strict';
angular
.module('mymodule.faultlist')
.controller('MainController', ['$rootScope', function ($rootScope) {
$rootScope.$on('newViewLoaded', function (event, metadata) {
$rootScope.metadata = metadata;
console.log('hello metacontroller metadata', metadata);
});
}])
.controller('ListController', ['faultlistservice', 'faultListConstants', '$scope', '$timeout', '$rootScope',
function (faultlistservice, faultListConstants, $scope, $timeout, $rootScope) {
$timeout(function () {
$scope.$emit('newViewLoaded', {
'title': faultListConstants.meta.title,
'description': faultListConstants.meta.description
});
}, 100);
}]);
})();
This is what the index.html roughly looks like:
.
.
<head ng-controller="MainController">
<div class="container main-content" ui-view >
</div>
..
This does not get triggered. I tried moving the $rootScope.$on block to the ListController and then the $rootScope.$on gets triggered. Why is this not working for the MainController or is there a better way of implementing this?