2016-08-16 207 views
0

我想要序列化传入和传出的参数。我发现我可以通过在$http config中更改transformRequesttransformResponse默认方法来实现。我的问题是这个。这两个函数内部的默认代码是什么?对于我的生活,我无法找到它在哪里。为了让我成功地序列化参数,我需要知道原始函数的样子。我目前正在运行Angular 1.5.X.谢谢。

angular.module('coolApp') 
.config(function ($httpProvider) { 
    $httpProvider.defaults.transformRequest = function(data){ 
    // What is the default code here? 
    // I need to add {security_token: 'secret_code'} to the request 
    // data sent to the server 

    } 

    $httpProvider.defaults.transformResponse = function(data){ 
    // What is the default code here? 
    // I need to remove the useless_params attribute in the response 
    } 
}); 

回答

1

默认transformRequesttransformResponse功能在$http提供商源代码中定义。

+0

虽然这在技术上是正确的,但代码是从源代码中找到的众多方法中借用的。我正在寻找在我的应用程序中使用的解决方案,而不仅仅是从源代码复制和粘贴。我希望AngularJS能够解决这个问题,因为毕竟他们允许你编辑这个函数。 – jason328

+0

请更新问题,然后,不清楚你的目标是什么。问题是你需要'知道'什么是功能,没有提到你需要这些知识。 – estus

+0

第一句读取“我想序列化传入和传出参数”。我会更新我的答案,以便更清楚。 – jason328

相关问题