AngularJS: Promises usage in angular application


Promises can be used to unnest asynchronous functions and allows one to chain multiple functions together – increasing readability and making individual functions, within the chain, more reusable.

function getCandidateCareer() {;
        .then(function (response) {
            if (
                $scope.countryList =;
            return careerDetailService.getJobTypeList();
        .then(function (response) {
            if (
                $scope.jobTypeList =;
            return careerDetailService.getExpertiseLevelList();
        .then(function (response) {
            if (
                $scope.expertiseLevelList =;
            return careerDetailService.getCandidateCareer();
        .then(function (response) {
            if ( 
                $ =[0];

If you look at code closely, in order to resolve chaining, next async call depends upon completion of previous ajax call, you consume the output as per need of current call and then execute the next async call in queue.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s