0
   $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();
            }
        })
    };

I want to call the second function if the first function returns true.

2 Answers 2

1

I'm not sure i understand the question but if you want to call functions synchronously (wait until one function finished) then use the callback functions.

$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")
}

Sign up to request clarification or add additional context in comments.

Comments

0

If it is a normal function you can write

if(function1()){
    function2();
}

If it is a HTTP or returns promise,

function1().then(function(){
    function2();
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.