I have one $cope to be used in another controller. So I used $broadcast event to share my value. The method worked fine and I could assign the value to a $scope variable that is been $broadcast. But the issue comes over her. I could not able to bind or access the assigned value of the $scope outside the $on event.
Edit 1:
I have same set of event that is working fine in the same module. But this one doesn't.
app.controller('ctrl0',function($scope,$rootScope) {
$rootScope.$broadcast($state.current.controller, { stateValue: $scope.data });
});
app.controller('ctrl1',function($scope,$rootScope) {
$rootScope.$on($state.current.controller, function (event, args) {
// This $scope binds in my view
$scope.mylabel = args.data;
});
$rootScope.$broadcast('myvariable', { search: $scope.searchvalue });
});
app.controller('ctrl2',function($scope,$rootScope) {
$rootScope.$on('myvariable', function (event, args) {
$scope.localscope = args.search;
/* This prints the value in the console.
This does not bind in my view. */
console.log($scope.localscope);
});
// This prints undefined in the console
console.log($scope.localscope);
});
I also tried by using $apply() function, but I didn't get the fruit.