我正在尝试从列表中删除帖子。删除功能通过串行传递到下面显示的删除功能来执行。
$scope.go = function(ref) {
$http.get("api/phone_recev.php?id="+ref)
.success(function (data) { });
}
执行该功能后,我需要重新加载用于列出列表的http.get请求。
$http.get("api/phone_accept.php")
.then(function (response) { });
执行功能后。整个列表将使用新的更新列表重新加载。有没有办法做这件事。
答案 0 :(得分:1)
function list_data() {
$http.get("api/phone_accept.php")
.then(function (response) {
console.log('listing');
});
}
$scope.go = function(ref) {
$http.get("api/phone_recev.php?id="+ref)
.success(function (data) {
// call function to do listing
list_data();
});
}
答案 1 :(得分:1)
试试这个
$scope.go = function(ref) {
$http.get("api/phone_recev.php?id="+ref)
.success(function (data) {
//on success of first function it will call
$http.get("api/phone_accept.php")
.then(function (response) {
});
});
}
答案 2 :(得分:0)
像@sudheesh Singanamalla所说的那样,通过在函数内再次调用相同的http.get请求解决了我的问题。
$scope.go = function(ref) {
$http.get("api/phone_recev.php?id="+ref).success(function (data) {
//same function goes here will solve the problem.
});}
});
答案 3 :(得分:0)
您可以使用$ q - 一种可以帮助您异步运行函数的服务,并在完成处理时使用它们的返回值(或异常)。
https://docs.angularjs.org/api/ng/service/ $ Q
在某些服务中。
app.factory('SomeService', function ($http, $q) {
return {
getData : function() {
// the $http API is based on the deferred/promise APIs exposed by the $q service
// so it returns a promise for us by default
return $http.get("api/phone_recev.php?id="+ref)
.then(function(response) {
if (typeof response.data === 'object') {
return response.data;
} else {
// invalid response
return $q.reject(response.data);
}
}, function(response) {
// something went wrong
return $q.reject(response.data);
});
}
};
});
在控制器中的某个地方运行
var makePromiseWithData = function() {
// This service's function returns a promise, but we'll deal with that shortly
SomeService.getData()
// then() called when gets back
.then(function(data) {
// promise fulfilled
// something
}, function(error) {
// promise rejected, could log the error with: console.log('error', error);
//some code
});
};