【发布时间】:2016-04-10 11:34:17
【问题描述】:
如何将 http.put 的响应对象作为 TestFunction 的返回值返回给控制器? http.get 的响应打印正常,但 putResponse 未定义。在调试期间,我可以看到 http.put 在服务器上更新数据。
testFunction: function (url, data) {
var etag;
var putResponse;
$http.get(url).then(function successCallback(response) {
if (response.data != null) {
etag = response.headers(['etag']);
$http.put(url, data, { headers: { 'If-Match': etag } }).then(function successCallback(response) {
putResponse = response;
}, function errorCallback(response) {
// handle error
});
}
else {
// handle error
}
}, function errorCallback(response) {
// handle error
});
console.log(putResponse);
}
【问题讨论】:
标签: angularjs angularjs-service angularjs-http