angular-bluebird
An AngularJS service for Bluebird promise library.
NOTE: Right now it's very experimental.
Why?
Because Bluebird is probably one of the best promise libraries around. Also, it IS the fastest.
Usage
npm install --save angular-bluebird
Example
This library assumes that you use Browserify
app.js:
var ngBluebird = require('angular-bluebird')
var app = angular.module('app', ['angular-bluebird'])
ngBluebird.trackDigests(app)
some-ctrl.js:
function SomeCtrl($scope, $window, $timeout, $bluebird) {
function asyncAskQuestion(question) {
var deferred = $bluebird.defer
$timeout(function() {
var result = $window.prompt(question)
if (typeof result == 'string') {
deferred.resolve({okPresssed: true, answer: result})
} else {
deferred.reject({okPressed: false})
}
}, 250)
return deferred.promise
}
$scope.askQuestion = function() {
var promise = asyncAskQuestion("Who is your favorite Teenage Mutant Ninja Turtle?")
promise.then(function(result) {
$window.alert('Cowabunga! Your favorite turtle is ' + result.answer)
}, function(result) {
$window.alert("You don't like the Ninja Turtles? What is wrong with you?")
})
}
}
License
MIT