【发布时间】:2015-09-02 06:01:35
【问题描述】:
我使用下面的代码。 dataService 的内容是我的应用程序中所有可能的 $http 。在控制器中,我使用了这个函数。该函数调用一个 Web Api 服务,这个服务被调用并返回正确的响应。在函数customerToggleSuccess 中,数据是undefined。我不明白为什么。
(function () {
angular.module('myApp')
.factory('dataService', ['$q', '$http']);
function dataService($q, $http,) {
return {
customerToggleActive: customerToggleActive
};
function customerToggleActive(customerId, index) {
var customer = {
"id": customerId,
"index": index
};
return $http({
method: 'POST',
url: 'api/customer/validtoggle/',
headers: {
},
transformResponse: function (data, headers) {
},
data: customer
})
.then(customerToggleData)
.catch(customerToggleError)
}
function customerToggleData(response) {
return response.data;
}
function customerToggleError(response) {
}
}
}());
(function () {
angular.module('myApp')
.controller('customerController', ['$scope', 'dataService', '$http', '$log', CustomerController]);
function CustomerController($scope, dataService, $http, , $log) {
var vm = this;
vm.activeToggle = function (customerId, index) {
dataService.customerToggleActive(customerId, index)
.then(customerToggleSuccess)
.catch(customerToggleCatch)
.finally(customerToggleComplete);
function customerToggleSuccess(data) {
$log.info(data);
}
function customerToggleCatch(errorMsg) {
}
function customerToggleComplete() {
}
}
}
}());
【问题讨论】:
-
在 $http 中配置了一个 transformRequest 函数,但不返回任何内容。也许这是问题? link
标签: javascript jquery angularjs asp.net-web-api