Thursday, 25 May 2017

Is it possible to wait for server response after a server call in angular JS?

When I Run the below code, Before getting server response, the rest of the logic code executed first. Which means before i'm getting $scope.Manage_SKUMaster & $scope.Manage_Carts values from database, rest of the logic code getting executed. So when the server call happens, it doesn't wait for the server response and run the other code.

HTML

<button class="btn btn-primary" ng-click="CartEstimation()" data-dismiss="modal"  title="Submit">Submit</button>

Controller

$scope.CartEstimation = function () {

        $http.get('/ManageSKUMaster').then(function (response) {               
            $scope.Manage_SKUMaster = response.data;
        });

        $http.get('/Manage_Cartshow').then(function (response) {               
            $scope.Manage_Carts = response.data;
        });

        if ($scope.Manage_SKUMaster.length > 0 && $scope.Manage_Carts.length > 0)
        { 
            //code for Logic               
        }
    };

So I want, If any server call happens, should wait till the response comes from the server. How can I achieve that? Is there anyway to do that in angularjs?

Thanks.



via Kavin

No comments:

Post a Comment