Created
February 5, 2014 18:00
-
-
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.
This file contains hidden or 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
<!-- 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