When I add a $broadcast in $rootScope and catch it to other controller, it is not reflecting any value to view. Example:
// on first ctrl.
controller('firstCtrl', ['$scope','$location', '$rootScope', function($scope, $location, $rootScope) {
$scope.myFunc = function() {
$rootScope.$broadcast('someEvent');
$location.path('/users');
}
}])
// On Users Page.
.controller('usersCtrl', ['$scope','$rootScope', function($scope, $rootScope) {
$scope.dataFilter = {};
$rootScope.$on('someEvent', function(event, b) {
$scope.callOnBroadcast();
});
// call this function on broadcast.
$scope.callOnBroadcast = function() {
$scope.dataFilter = {
types: [
{key: 'tags', val: 'Collections'},
{key: 'prices', val: 'Price'},
{key: 'ratings', val: 'Rating'},
{key: 'designers',val: 'Designer'}
],
data: {tags: [], prices: [], ratings: [], designers: []}
};
$scope.$apply();
};
}])
<h4 data-ng-repeat="ftr in dataFilter.types">
{{ftr.val}}
</h4>
When I Use MyFunc function on firstCtrl, it will redirect me to user's page, also broadcast function run.
On users page, I Use $scope.callOnBroadcast() when broadcast is on, but it is reflecting any change on view page even I use $scope.$apply().
Where am I wrong ?
$rootScope$broadcast('someEvent');if controller hierarchy is not there..Please add html to see how your controller hierarchy