AngularJS RESTful $resource服务

我们如果要使用$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:'/'});
    } ]);
原文地址:https://www.cnblogs.com/lihaozhou/p/3667316.html