首页 > 代码库 > AngularJS篇 <<The complete guide of AngularJS>>笔记

AngularJS篇 <<The complete guide of AngularJS>>笔记

 

定义服务的多种方式:

// 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>>笔记