$resource transformResponse 不起作用 [英] $resource transformResponse not working

查看:23
本文介绍了$resource transformResponse 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一个简化的 $resource 示例(改编自 Angular 站点):

Got a simplified $resource example here (adapted from Angular site):

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') 永远不会被调用.这是为什么?其他一切正常.

The question is that the line console.log('transforming') is never getting called. Why is that? Everything else works fine.

现场小提琴这里.

推荐答案

此功能仅在 AngularJs 1.1.2 或更高版本中可用.它在 1.1.1 或更早版本的 AngularJs 中不可用.

This functionality is only available in the 1.1.2 or later versions of AngularJs. It is not available in the 1.1.1 or earlier versions of AngularJs.

这篇关于$resource transformResponse 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆