Created
January 5, 2015 19:38
-
-
Save willread/3ac901949c0b7b7d999c to your computer and use it in GitHub Desktop.
Use watchers in an angular service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app') | |
.service('myService', function($rootScope) { | |
// Inject an isolate scope into the rootscope to | |
// enable us to use $watch to from a service | |
this.scope = $rootScope.$new(true); | |
this.scope.myService = this; | |
this.scope.$watch('something', function() {}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment