Skip to content Skip to sidebar Skip to footer

How To Work With Promises That Rely On Other Promises Being Fulfilled?

I have an AngularJS promise (users) that relies on another promise (userTypes) being fulfilled before I can manipulate it. The results from both promises are being used in the cont

Solution 1:

Extrapolating from other promise architectures, you can most likely return a promise from then, which then becomes the object the next .then is applied to.

// this is all in my controller somewhere
userService.getUserTypes().then(function( data ) {

    $scope.userTypes = data;

}).then(function(data) {

    return userService.getUsers();

}).then(function( data ) {

    $scope.users = data;

    for( var user in $scope.users ) {

        $scope.users[ user ].userType = $filter("filter")( $scope.userTypes, { id: $scope.users[ user ].userTypeID })[0];

    }

});;

Post a Comment for "How To Work With Promises That Rely On Other Promises Being Fulfilled?"