$scope.PrintOWTickets = function (TicketNo, MobilNo) {
$http({
method: "GET",
url: $scope.ip + '/getPrintTicekt?TicketNo=' + TicketNo + '&PassengeMobile=' + MobilNo + '&PassengeEmail=' + MobilNo + '&ClientId=' + $scope.clientidFromFactory + ''
}).then(function (response) {
$scope.PrintOW = response.data;
if (response.data.error == 1) {
alert("Error");
}
else {
function1(); // if it is success then call function2
function2();
}
})
};
这里我想调用函数,如果它返回true。这种方式我想调用多个函数..是真的还是不正确?
答案 0 :(得分:1)
我不确定我是否理解这个问题,但是如果你想同步调用函数(等到一个函数完成),那么使用callback
函数。
$scope.PrintOWTickets = function(TicketNo, MobilNo) {
$http({
method: "GET",
url: $scope.ip + '/getPrintTicekt?TicketNo=' + TicketNo + '&PassengeMobile=' + MobilNo + '&PassengeEmail=' + MobilNo + '&ClientId=' + $scope.clientidFromFactory + ''
}).then(function(response) {
$scope.PrintOW = response.data;
if (response.data.error == 1) {
alert("Error");
} else {
function1(function() {
function2();
}); // if it is success then call function2
}
})
};
function function1(callback) {
console.log("one")
// do whaterver and return the callback
callback();
}
function function2() {
console.log("two")
}
function1(function() {
function2();
});
function function1(callback) {
console.log("one")
// do whaterver and return the callback
callback();
}
function function2() {
console.log("two")
}

答案 1 :(得分:0)
如果是正常功能,你可以写
if(function1()){
function2();
}
如果是HTTP或返回承诺,
function1().then(function(){
function2();
});