angular-es6-promises
angular-es6-promises copied to clipboard
ECMAScript 6 promises for Angular.JS
angular-es6-promises
ECMAScript 6 promises for Angular.JS.
Copyright (C) 2014, Uri Shaked [email protected].
Usage
Include angular-es6-promises.js
in your application.
<script src="bower_components/angular-es6-promises/angular-es6-promises.js"></script>
Add the angular-es6-promises
module as a dependency to your app:
var myapp = angular.module('myapp', ['angular-es6-promises']);
Inject the Promise
factory anywhere you need to create a new promise, then
call the Promise
constructor with an executor function, as shown below:
myApp.service('someService', function(Promise) {
this.doSomethingAsync = function() {
return new Promise(
function(resolve, reject) {
someAsyncFunction(function(result) {
if (result) {
resolve(result);
} else {
reject(new Error('ASync function did not return a result'));
}
});
}
);
}
});
License
Released under the terms of MIT License.