diff --git a/ngStorage.js b/ngStorage.js index ffffda9..88550c4 100644 --- a/ngStorage.js +++ b/ngStorage.js @@ -190,6 +190,8 @@ } _last$storage = angular.copy($storage); + + $rootScope.$broadcast('$ngStorageChanged'); } }, $supported: function() { diff --git a/test/spec.js b/test/spec.js index e8fa07f..3dbaa84 100644 --- a/test/spec.js +++ b/test/spec.js @@ -153,6 +153,27 @@ describe('ngStorage', function() { }); + it('should broadcast a $ngStorageChanged event after applying changes', + function (done) { + + initStorage({'ngStorage-entry': '"initial"'}); + + var changedHandlerInvoked = false; + $rootScope.$on('$ngStorageChanged', function () { + changedHandlerInvoked = true; + }); + + $storage.entry = 'updated'; + $rootScope.$digest(); + + $timeout.flush(); + + setTimeout(function () { + expect(changedHandlerInvoked).to.equal(true); + done(); + }, 125); + }); + describe('when $reset is called with no arguments', function() { beforeEach(function(done) {