Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The most common and flexible way to create a service uses the angular.module API factory:

Code Block
javascript
javascript
// 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;
      }
    }

  }]);

...