angularjs - How to get prevent multiple promises from different functions -
in angular-app
, have 3 queries, each depends on others. putting promise()
each of them. in case how can $q.all
depended promise once done?
can clarify me, please?
here code :
"use strict"; angular.module("tcpapp") .controller("projectsummarycontroller", ['$scope', '$routeparams', '$location', 'server', 'modalservice', '$q', function ( $scope, $routeparams, $location, server, modalservice, $q ) { $scope.projectid = $routeparams.projectid; $scope.subprojectid = $routeparams.subprojectid; $scope.phaseid = 0; $scope.disciplineid = 0; $scope.contractorid = 0; $scope.queryconractorinfo = function ( contractorid ) { server.contractorinfo.get({ projectid:$scope.projectid, subprojectid : $scope.subprojectid, contractid : $scope.contractorid, disciplineid : $scope.disciplineid, staticid : 0 /* @ present static */ }).$promise.then(function ( contractorinfo ) { $scope.contractorinfo = contractorinfo; }) } $scope.queryconractorlist = function ( phaseid, disciplineid ) { var base = 'http://azvsptcsdev02:678/_vti_bin/cpmd.webservice/projectinfoservice.svc/contracts/' console.log( base+$scope.projectid+'/'+$scope.subprojectid+'/'+phaseid+'/'+disciplineid ); server.contractorslist.query( { projectid:$scope.projectid, subprojectid : $scope.subprojectid, phaseid : phaseid, disciplineid: disciplineid }).$promise.then(function ( contractorslist ) { $scope.contractorid = contractorslist[0].id; //setting first contractor default; $scope.queryconractorinfo( $scope.contractorid ); }); } $scope.queryproject = function ( prjid, subprjid ) { server.projectsummary.get({id:$scope.projectid}) .$promise.then(function (data) { //only setting phase id , desciple id list of contractors $scope.phaseid = data.phaseids[0].id; //setting first phase default; $scope.disciplineid = data.disciplineids[0].id; //setting first descipline default; $scope.queryconractorlist( $scope.phaseid, $scope.disciplineid ); }); } if($scope.projectid) { $scope.queryproject(); } $q.all([ $scope.queryproject, $scope.queryconractorlist, $scope.queryconractorinfo ]) .then(function ( data1, data2, data3 ) { console.log( data1, data2, data3 );// nothing here! }) }]);
what best practice handle this?
Comments
Post a Comment