AngularJS $shared
AngularJS $shared
To make life easier for some AngularJS developers, they sometimes use the $rootScope to store data. To be fair, AngularJS scopes are a bit tricky at first and sometimes do not work according to plan. It is not a good idea to pollute the $rootScope and should only be used in certain scenarios. I decided to write a wrapper service / factory for this reason.



      $shared.set('someKey', 'hello!')
      $shared.get('someKey')

      $shared.watch('someKey', function(newVal) {
        alert(newVal);
      });

      $shared.on($scope, "someSignal", function(event, data) {
        alert(data)
      });

      $shared.emit("someSignal", "someMessage");
      

The $shared factory / service is only around 50 lines of code but it includes some of the best practices and tweaks when using the $rootScope.

Source Code
You can view the source code here.