Skip to content

Instantly share code, notes, and snippets.

@willread
Created January 5, 2015 19:38
Show Gist options
  • Save willread/3ac901949c0b7b7d999c to your computer and use it in GitHub Desktop.
Save willread/3ac901949c0b7b7d999c to your computer and use it in GitHub Desktop.
Use watchers in an angular service
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