JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 98
  • Score
    100M100P100Q70273F
  • License MIT

Add `spread` method to the promise of $q.all

Package Exports

  • angular-q-spread

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (angular-q-spread) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

GitHub version Bower version NPM version

Build Status

angular-q-spread

Add spread method to all promises created by the $q service.

spread can be used as a replacement for then. Similarly, it takes two parameters, a callback when all promises are resolved and a callback for failure. The resolve callback is going to be called with the result of the list of promises passed to $q.all as separate parameters instead of one parameters which is an array.

spread can be chained onto every promise.

#Compatibility This plugin has been tested with Angular 1.2 and 1.3

#Usage Add $q-spread as dependency when creating your angular module.

#Example angular.module('test', ['$q-spread']);

function TestCtrl($scope, $q, MyService) {
    $scope.name = null;

    function firstCallback(firstname, lastname)
    {
        return firstname + ' ' + lastname;
    }

    function anotherCallback(fullname)
    {
        $scope.name = fullname;
    }

    function failureCallback(reason)
    {
        alert('Could not load data: ' + reason);
    }
    
    $q
        .all([
            MyService.getFirstname(),
            MyService.getLastname()
        ])
        .spread(firstCallback)
        .then(anotherCallback)
        .catch(failureCallback);
};

TestCtrl.$inject = ['$scope', '$q', 'MyService'];

angular.module('test').controller('TestCtrl', TestCtrl);

License

This Angular module has been published under the MIT license