I'm doing a broadcast and on listening to the broadcast i'm trying to updated a variable on the scope that I wanted to display on the view, but the changes are not being reflected in the view immediately, until I click on the UI. Anyone know what should be done at this point, I don't want to use $apply. Here, please find my code.
rApp.factory('pService', ['$http', '$rootScope', '$sanitize',
function ($http, $rootScope, $sanitize) {
var pService = {};
//Some other code
pService.Update=function(status)
{
if(status.LastItemId!=undefined)
{
pService.disItemId = status.LastItemId;
$rootScope.$broadcast('updated',pService.disItemId);
}
}
//Some other code
return pService;
});
rApp.controller('dController', ['$scope','$rootScope' 'pService' ,dController]);
function dController($scope,$rootScope, pService) {
$rootScope.$on('updated',function (event, data) {
$scope.lastItemId = data; // I want to display the lastItemId on UI
})
});