我很好奇如何在http.get服务调用中添加条件语句。
例如我的服务电话:
$http.get(baseURL + "/api/complaints/" + $scope.Case + "/clists")
.then(function (cl) {
//success
$scope.cl = []
$scope.cl = cl;
}, function (err) {
//failure
var errorMessage = "Cannot post checklists" + err;
})
.finally(function () {
var isBusy = false;
});
我想添加一个条件来说明$ scope是否不存在这些clists.Case,请运行post service调用以创建一个clist。看起来像这样:
$http.get(baseURL + "/api/complaints/" + $scope.Case + "/clists"")
.then(function (cl) {
//success
$scope.cl = []
if ($scope.cl.ID == null) {
$http.post(baseURL + "/api/complaints/" + $scope.Case + "/clists")
$scope.cl = cl;
}
else {
$scope.cl = cl;
}
}, function (err) {
//failure
var errorMessage = "Cannot post checklists" + err;
})
.finally(function () {
var isBusy = false;
});
看起来不错,除了这部分。您需要为帖子的promise添加一个回调函数:
if ($scope.cl.ID == null) {
$http.post(baseURL + "/api/complaints/" + $scope.Case + "/clists")
.then(function(cl) {
$scope.cl = cl;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句