...
The most common and flexible way to create a service uses the angular.module API factory:
Code Block | ||||
---|---|---|---|---|
| ||||
// Example service that holds on to the current_user for the lifetime of the app angular.module('myApp.services', []) .factory('UserService', ['$http', function($http) { var current_user; return { getCurrentUser: function() { return current_user; }, setUsername: function(user) { current_user; = user; } } }]); |
...