您的位置:首页 > Web前端 > AngularJS

AngularJS RESTful $resource服务

2014-04-15 21:09 218 查看
我们如果要使用$resource服务,先要引用resource文件

在模块里面拿到数据

再利用模块注入的形式

angular.module('phonecatServices', ['ngResource']).
factory('Phone', function ($resource) {
return $resource('contact/phone.json', {}, {
query: { method: 'GET', params: { id: 'phones' }, isArray: true }
});
});


在模块里面注入是使用

angular.module("news", ['ngRoute', 'phonecatServices']).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/', { templateUrl: 'partials/list.html', controller: newsListController }).
when('/news/:id', { templateUrl: 'partials/detail.html', controller: newsDetailController }).
otherwise({redirectTo:'/'});
} ]);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: