Possibly unhandled rejection in Angular 1.6
This has been fixed with fix($q): Add traceback to unhandled promise rejections — Commit 316f60f and the fix is included in the v1.6.1 release.
This has been fixed with fix($q): Add traceback to unhandled promise rejections — Commit 316f60f and the fix is included in the v1.6.1 release.
I have been doing this with forkJoin import {Observable} from ‘rxjs/Observable’; import ‘rxjs/add/observable/forkJoin’; Observable.forkJoin( this.http.get(‘./friends.json’).map((res: Response) => res.json()), this.http.get(‘./customer.json’).map((res: Response) => res.json()) ) .subscribe(res => this.combined = {friends: res[0].friends, customer: res[1]}); Some more info here: http://www.syntaxsuccess.com/viewarticle/angular-2.0-and-http
Is this the right approach? Yes. The use of memoisation on functions that return promises a common technique to avoid the repeated execution of asynchronous (and usually expensive) tasks. The promise makes the caching easy because one does not need to distinguish between ongoing and finished operations, they’re both represented as (the same) promise for … Read more
Update: Due to refactoring of $q this is now possible although not documented: promise.$$state.status === 0 // pending promise.$$state.status === 1 // resolved promise.$$state.status === 2 // rejected Original: Unlike most promise libraries (Bluebird,Q, when, RSVP etc), $q does not expose a synchronous inspection API. There is no way to achieve this from the outside. … Read more
Old question but I had the same problem and stumbled on this in ui-router’s FAQ section If you are having issues where a trivial error wasn’t being caught because it was happening within the resolve function of a state, this is actually the intended behavior of promises per the spec. errors within resolve. So you … Read more
This is possible, and even quite easy! Well, if we look at how Angular’s own promises work, we need to get Bluebird to $evalAsync somewhere in order to get the exact same behavior. If we do that, the fact both implementations are Promises/A+ compliant means we can interop between $q code and Bluebird code, meaning … Read more
How to simply return a pre-resolved promise in AngularJS Resolved promise: return $q.when( someValue ); // angularjs 1.2+ return $q.resolve( someValue ); // angularjs 1.4+, alias to `when` to match ES6 Rejected promise: return $q.reject( someValue );
Your second code example is the right way to go. Because the scope changes in the new function, this changes too, so you’re right to make a reference to this outside of the function. The reason it failed is because the function is using a that you passed into the function rather than the global … Read more
I believe since the promise library is based on Q implementation, as soon as the first promise gets rejected, the reject callback is called with the error. It does not wait for other promises to resolved. See documentation of Q https://github.com/kriskowal/q. For Q.all this is what is mentioned The all function returns a promise for … Read more
You need to add an additional parameter: $http.get(url).then( function(response) { console.log(‘get’,response) }, function(data) { // Handle error here })