javascript - Process http get request completely before click event -


i have following javascript code:-

$scope.fav_bill_details=function (id1,id2,bill_id) { document.getelementbyid(id2).style.display="none"; $scope.getactivebill(); document.getelementbyid(id1).style.display="block"; $scope.getbilldetails(bill_id); $timeout(function(){     var btn=angular.element(document.getelementbyid(bill_id));     angular.element(document.getelementbyid(btn.id)).trigger('click');     }); }; 

as can see above there 2 function call above:- $scope.getactivebill(); , $scope.getbilldetails(bill_id);, both of these functions has http requests. data , process , store in $scope variables. want these request completed before trigger click event above. have implemented promises in both function. click finishes first , http requests completed. how can achieve above requirement??

you need use promises, this:

$scope.fav_bill_details=function (id1,id2,bill_id) {     document.getelementbyid(id2).style.display="none";     $scope.getactivebill().then(function() {         document.getelementbyid(id1).style.display="block";         return $scope.getbilldetails(bill_id);     }).then(function () {         var btn=angular.element(document.getelementbyid(bill_id));                            angular.element(document.getelementbyid(btn.id)).trigger('click');     }); 

in example call asynchronous functions don't wait them finish, solves it.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -