title: Update root scope from an AngularJS directive
body: <p>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.</p>
  
  <pre><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); 
              });     
          }
      }
  });
  </code></pre>
  
  <p>This is my main controller</p>
  
  <pre><code>app.controller('MainCtrl', function($scope,$rootScope) {
   $scope.totalCost = 'workinggg';
   $rootScope.$on('go', function() {alert();
          $scope.totalCost = 'working';
      });
  });
  </code></pre>
  
  <p>How to update the rootscope.</p>