Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ---------------------------------------------------------------------------------------------------------------------
- // PromiseProxy - A proxy object that wraps a promise, and exposes `pending`, `result` and `error` properties. This is
- // most useful when setting results of promises on the scope directly, so you can work with them in your templates.
- //
- // @module promise-proxy.js
- // ---------------------------------------------------------------------------------------------------------------------
- function PromiseProxyFactory(promise)
- {
- var proxy = {
- pending: true,
- promise: promise
- };
- promise.then(
- function(result)
- {
- proxy.pending = false;
- proxy.result = result;
- },
- function(error)
- {
- proxy.pending = false;
- proxy.error = error;
- });
- return proxy;
- } // end PromiseProxyFactory
- // ---------------------------------------------------------------------------------------------------------------------
- angular.module('promise-proxy', []).value('promise-proxy', PromiseProxyFactory);
- // ---------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement