Questions tagged [angular-promise]

Angular's $q promises provide a powerful abstraction over flow control. If you tag your question with this tag, consider also tagging it with "promise" tag. This tag is also appropriate for questions about angular and promises not relaying to $q directly.

Angular's $q promises provide a powerful abstraction over flow control. If you tag your question with this tag consider also tagging it with the promise tag.

This tag is also appropriate for questions about angular and promises not relaying to $q directly.

2114 questions
35
votes
3 answers

Caching a promise object in AngularJS service

I want to implement a dynamic loading of a static resource in AngularJS using Promises. The problem: I have couple components on page which might (or not, depends which are displayed, thus dynamic) need to get a static resource from the server. Once…
andrew.fox
  • 7,435
  • 5
  • 52
  • 75
33
votes
9 answers

Possibly unhandled rejection in Angular 1.6

I have a code with AngularJS: service.doSomething() .then(function(result) { //do something with the result }); In AngularJS 1.5.9 when I have error in the .then() section like: service.doSomething() .then(function(result) { var x…
33
votes
2 answers

Angular2 Observable - Await multiple function calls before proceeding

I am trying to improve my knowledge of Angular2 by migrating an application currently written in Angular1/AngularJS. One feature in particular has me stumped. I am trying to replicate a feature where a calling function waits to proceed until the…
Benjamin McFerren
  • 822
  • 5
  • 21
  • 36
30
votes
3 answers

Angular $q .catch() method fails in IE8

I'm experiencing a weird bug on IE8 while trying to catch a promise reject (promise returned by a basic ngResource call) : This code work with .then(success, fail) syntax : promise.then(function(response) { // success }, function(response) { //…
29
votes
5 answers

Immediately return a resolved promise using AngularJS

I'm trying to get my head around promises in JavaScript (in particular AngularJS). I have a function in a service, let's call it fooService, that checks if we've loaded some data. If it has, I just want it to return, and if we haven't, we need to…
samturner
  • 2,213
  • 5
  • 25
  • 31
25
votes
2 answers

What's the equivalent of Angular's $q in Angular2?

What's the equivalent of Angular's $q in Angular2? Specifically, I'm looking for $q.when, which allowed you to do something like: return $q.when(['TestResponse']);
David
  • 15,652
  • 26
  • 115
  • 156
25
votes
3 answers

$q promise error callback chains

In the following code snippet error 1 and success 2 will be logged. How can I can I propagate error callbacks being invoked rather than the success callbacks being invoked if the original deferred is rejected. angular.module("Foo",…
Steven Wexler
  • 16,589
  • 8
  • 53
  • 80
21
votes
1 answer

Intercept Unathorized API calls with Angular

I am trying to intercept the 401 and 403 errors to refresh the user token, but I can't get it working well. All I have achieved is this interceptor: app.config(function ($httpProvider) { $httpProvider.interceptors.push(function ($q, $injector)…
VanPersie
  • 65
  • 3
  • 13
20
votes
2 answers

Promises - error callback vs. catch

Can somebody tell me if there is a difference between using an error callback vs. a catch function, when using $q.promise please? E.g. are the two snippets of code functionally equivalent? function doSomething0() { var deferred = $q.defer(); …
keldar
  • 6,152
  • 10
  • 52
  • 82
19
votes
3 answers

Typescript async/await and angular $q service

New TypeScript async/await feature uses ES6 promises. AngularJS uses $q service promises with slightly different interface. Is there any way to use TypeScript async/await feature with $q service promises?
Random
  • 3,807
  • 2
  • 30
  • 49
18
votes
3 answers

Is this a "Deferred Antipattern"?

I'm finding it hard to understand the "deferred antipattern". I think I understand it in principal but I haven't seen a super simple example of what a service, with a differed promise and one with antipattern, so I figured I'd try and make my own…
Aleski
  • 1,402
  • 5
  • 16
  • 30
18
votes
7 answers

Make angular.forEach wait for promise after going to next object

I have a list of objects. The objects are passed to a deferred function. I want to call the function with the next object only after the previous call is resolved. Is there any way I can do this? angular.forEach(objects, function (object) { //…
Razvan
  • 303
  • 1
  • 4
  • 11
18
votes
5 answers

Stop request in angularjs interceptor

How can I stop a request in Angularjs interceptor. Is there any way to do that? I tried using promises and sending reject instead of resolve ! .factory('connectionInterceptor', ['$q', '$timeout', function($q, $timeout) { var…
vipulsodha
  • 624
  • 1
  • 9
  • 27
18
votes
5 answers

AngularJS - Promises rethrow caught exceptions

In the following code, an exception is caught by the catch function of the $q promise: // Fiddle - http://jsfiddle.net/EFpn8/6/ f1().then(function(data) { console.log("success 1: "+data) return f2(); }) .then(function(data)…
VitalyB
  • 12,397
  • 9
  • 72
  • 94
17
votes
3 answers

finally block in angular 2 promise

I observe that In angular 2 there is no finally block for promise API angular 1 : loadUsers() { fetch('/api/users').then((response) => { return response.json(); }).then((data) => { this.users = data; }).catch((ex) => { …
Dmehro
  • 1,269
  • 1
  • 16
  • 29