I have a directive, which watches for a inout box for old and new value. I would want to update the rootscope value here "total" . I tried to use all, that I knew like $rootScope, broadcast the message, emit the message. Here is the code.
app.directive('costCheck',function($compile,$rootScope,$timeout){
$rootScope.gName= "What did i buy?";
return{
restrict: 'A',
link: function(scope,element,attrs){
attrs.$observe('costCheck',function(value){
});
scope.$watch('cost',function(oldval,newval){alert(attrs.name);
alert(oldval+'--'+newval);
var message = {type: 'channel', action: 'create', data: { name: "ssss", id: 0}};
$rootScope.$broadcast('get',message);
});
}
}
});
This is my main controller
app.controller('MainCtrl', function($scope,$rootScope) {
$scope.totalCost = 'workinggg';
$rootScope.$on('go', function() {alert();
$scope.totalCost = 'working';
});
});
How to update the rootscope.
goand broadcastingget.scope : { value : '=value'}and avoid nastybroadcast/emits.