Skip to content

Instantly share code, notes, and snippets.

@frangucc
Created February 5, 2014 18:00
Show Gist options
  • Save frangucc/8829615 to your computer and use it in GitHub Desktop.
Save frangucc/8829615 to your computer and use it in GitHub Desktop.
Adding a Service Function that can be called from a controller from anywhere in an Angular.js app.
<!-- Screencast on how to add a service function -->
<div ng-controller="SayMyService">{{ say() }}</div>
.factory('myService', function () {
return {
say: function () {
return "Hello World";
}
}
})
.controller('SayMyService', function ($scope, myService) {
$scope.say = myService.say;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment