标签:
定义服务的多种方式:
// factory方式
angular.module(‘myApp‘, []).factory(‘UserService‘, function($http) { var current_user; return { getCurrentUser: function() { return current_user; }, setCurrentUser: function(user) { current_user = user; } } });
// service: contructor方式 var Person = function($http) { this.getName = function() { return $http({ method: ‘GET‘, url: ‘/api/user‘ }); }; }; angular.service(‘personService‘, Person);
AngularJS篇 <<The complete guide of AngularJS>>笔记
标签:
原文地址:http://www.cnblogs.com/diydyq/p/4177353.html