Skip to content

Instantly share code, notes, and snippets.

@mgonto
Created May 1, 2013 18:11
Show Gist options
  • Select an option

  • Save mgonto/5497061 to your computer and use it in GitHub Desktop.

Select an option

Save mgonto/5497061 to your computer and use it in GitHub Desktop.
Model Service
angular.module("test").service("Greeting", function() {
this.greet = null;
this.greetTo = function(name) {
this.greet = "Hello " + name;
}
});
angular.module("test").controller("TestCtrl", function(Greeting) {
$scope.greeting = Greeting;
$scope.$watch("greeting", function(){
// The model has changed. Do something
});
$scope.greeting.greetTo("Gonto");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment