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
17
votes
1 answer

wait for promises in onbeforeunload

I want to send a $http.get if the page gets closed. Then I stumbold upon a problem where promises can't get resolved because if this one last method returns, the page gets destroyed. The following does not work because onbeforeunload can't resolve…
17
votes
3 answers

Chain Angular $http calls properly?

I have been reading about $q and promises for days now and I seem to understand it...somewhat. I have the following situation in practice: An $http request is made and checks whether a subsequent call can be made. If the first call fails, return…
VSO
  • 11,546
  • 25
  • 99
  • 187
17
votes
7 answers

How do I sequentially chain promises with angularjs $q?

In the promise library Q, you can do the following to sequentially chain promises: var items = ['one', 'two', 'three']; var chain = Q(); items.forEach(function (el) { chain = chain.then(foo(el)); }); return chain; however, the following doesn't…
redgeoff
  • 3,163
  • 1
  • 25
  • 39
16
votes
3 answers

Promise chaining when using $timeout

I'm trying to understand the promise API and chaining, particularly the timing when $timeoutis used with .then(). What I had expected from the following is that since $timeout returns a promise, .then() would not be called until it had resolved.…
twip
  • 638
  • 2
  • 9
  • 20
15
votes
3 answers

Setting a timeout for each promise within a promise.all

I am able to successfully perform a Promise.all, and gracefully handle resolves and rejects. However, some promises complete within a few milliseconds, some can/could take a while. I want to be able to set a timeout for each promise within the…
Oam Psy
  • 8,555
  • 32
  • 93
  • 157
15
votes
2 answers

How can I access a variable outside a promise `.then` method?

I'm working on a Spotify app. I'm able to login and get my token. My problem is I cannot access a variable outside the method. In this case "getCurrentUser" This is my method: function getUser() { if ($localStorage.token == undefined) { throw…
Rodolfo R
  • 397
  • 1
  • 3
  • 17
14
votes
3 answers

Swallowed message : Error: Uncaught (in promise): [object Undefined]

My login component briefly displays before being removed by an error message about an undefined object in a promise. Here is the promise definition: static init(): Promise { KeycloakClientService.auth.loggedIn = false; return new…
Stephane
  • 11,836
  • 25
  • 112
  • 175
14
votes
3 answers

Why do we prefer using $q in angular instead of $http

I am currently using $q service from angular to make API calls like this: var deferred = $q.defer(); $http.get(config.apiHost + details.url) .success(function (data) { deferred.resolve(data); }).error(function (msg) { …
Bhushan Goel
  • 2,114
  • 3
  • 19
  • 31
13
votes
5 answers

Subscription to promise

In my Angular 7 application I have next function: getUserData(uid) { return this.fireStore.collection('users').doc(uid).valueChanges().subscribe(data => { this.writeCookie(data) this.currentUser = data; }) } And I want to…
Volodymyr Humeniuk
  • 3,411
  • 9
  • 35
  • 70
13
votes
3 answers

How to destroy unresolved promise

Have a look into the code snippet $scope.getSongs = function(keyword){ songServices.getSongList(keyword).then( function(resp){ $scope.songList = resp.data.songList; } ); } Here getSongList simply returns…
Suraj Khurana
  • 392
  • 3
  • 14
13
votes
1 answer

angular $http / jquery complete equivalent

Is there a way to emulate jquery 'complete' callback with angular $http module? I have some code I would like to execute no matter whether the request succeeded or failed and at the moment I find myself having to write…
Renaud
  • 4,569
  • 7
  • 41
  • 72
12
votes
4 answers

Convert promise in JSON object

I have a problem converting the promise returned by the service to the controller. What I want is to create an array of JSON objects from the data contained in promise. Here is what I receive in the controller: Here is the line that is used for…
VitezKoja
  • 163
  • 1
  • 1
  • 6
12
votes
3 answers

What is the HTTP promise object in AngularJS?

Although I am working with the HTTP promise object in AngularJS, I don't have a clear concept of what an HTTP promise object actually is and what the is difference between an HTTP promise object and a traditional object in AngularJS! Would anybody…
TanvirArjel
  • 30,049
  • 14
  • 78
  • 114
12
votes
3 answers

Angular promise on multiple $http

I am trying to do multiple $http call and my code looks something like this: var data = ["data1","data2","data3"..."data10"]; for(var i=0;i
user1995781
  • 19,085
  • 45
  • 135
  • 236
12
votes
1 answer

Executing then after catch

I have the following fiddle: http://jsfiddle.net/thelgevold/3uv9nnjm/6/ angular.module('hello',[]).controller('helloController',function($q){ console.clear(); function someService(){ var deferred = $q.defer(); …
TGH
  • 38,769
  • 12
  • 102
  • 135