$resource这里有一个简化的示例(改编自Angular网站):
$resource
angular.module('project', ['mongolab']); function ListCtrl($scope, Project) { $scope.projects = Project.test(); } angular.module('mongolab', ['ngResource']). factory('Project', function ($resource) { var url, dfParams, actions; url = 'https://api.mongolab.com/api/1/databases' + '/angularjs/collections/projects/:id'; dfParams = { apiKey: '4f847ad3e4b08a2eed5f3b54' }; actions = { test: { method: 'GET', isArray: true, transformResponse: function (response) { // line is never getting called console.log('transforming'); return response; } }; var Project = $resource(url, dfParams, actions); return Project; });
问题 是该线路console.log('transforming')永远不会被呼叫。这是为什么?其他一切正常。
console.log('transforming')
在这里住小提琴。
此功能仅在1.1.2或更高版本的AngularJs中可用。它在AngularJs的1.1.1或更早版本中不可用。