码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2014-12-22 00:50:06      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

 

定义服务的多种方式:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!