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
5
votes
2 answers

How to use angular 2 service which returns http promise

I have a trouble with angular 2 here. I use service that return promise but when i try to retrive the response i got an error. i was read this this stact question this my code. this is HotelService.ts import { Injectable } from…
Cecep
  • 87
  • 3
  • 10
5
votes
2 answers

Chaining multiple promises, including Promise.all

I have a requirement which requires chaining of Promises. In my Ionic app, I need to iterate over a list of files and zip them. Then the zip needs to be stored on the device itself (iPhone in this case). I already have the list of files that need to…
kayasa
  • 2,055
  • 8
  • 37
  • 63
5
votes
1 answer

Get data from JSON with Angular2 Promise

I'm trying to get data from a JSON file following the http tutorial from the Angular2 documentation: Service: import { Injectable } from '@angular/core'; import { Headers, Http } from '@angular/http'; import 'rxjs/add/operator/toPromise'; import {…
smartmouse
  • 13,912
  • 34
  • 100
  • 166
5
votes
2 answers

Why is $scope.someArray.push not a valid function to pass to .then on $q.promise

Relevant fiddle: https://jsfiddle.net/tqf4zea7/1/ I'm using $q in an angular controller. To test some scenarios, I created an array on the scope to push messages to: $scope.messages = []; I have set up a function that returns a $q function as…
sonicblis
  • 2,926
  • 7
  • 30
  • 48
5
votes
4 answers

Order of promises in AngularJS

Question: Is there an "easy" way to cancel ($q-/$http-)promises in AngularJS or determine the order in which promises were resolved? Example I have a long running calculation and i request the result via $http. Some actions or events require me to…
H W
  • 2,556
  • 3
  • 21
  • 45
5
votes
2 answers

How to access variable declared inside promise in AngularJS

I am new to the AngularJS, I need to access the variable which is assigned inside the promise in Javascript this.reqData= this.profileService.getData(); var resp1 = angular.fromJson(this.reqData); this.data1; var that =…
Prabhu
  • 394
  • 1
  • 7
  • 23
5
votes
4 answers

Using the $q service with angular

I still can't understand the role of using the $q service, (what exactly will it add) if you want to create a service that need to call only one API via http , in this situation I don't know why shouldn't I just do the following (without using $q) :…
5
votes
2 answers

Angular $q.all gets called after first promise finished

I'm trying to use $q.all to wait until all promises are resolved but it's called after first promise is finished! What I'm doing wrong? function sendAudits(audits) { var promises = []; $scope.sendAudits = { progress: 0 }; …
Miquel
  • 8,339
  • 11
  • 59
  • 82
5
votes
1 answer

Chained promises and prototype `this`

I'm having a hard time to get promises to work with the right this scope inside prototypes. Here is my code: 'use strict'; angular.module('testApp').factory('UrlSearchApi', function($resource, URL_SEARCH_API, PAGE_SIZE, $q){ var resource =…
Adrian
  • 9,102
  • 4
  • 40
  • 35
5
votes
1 answer

AngularJS execution order with `$q` -- Chaining Promises

Following Approach works: $q.when() .then(checkCookieToken) // check if cookie already exists e.g. in cookie .then(setHeader) // set Header with REST-Token e.g from cookie .then(checkTokenOnline) …
user2227400
5
votes
4 answers

How can I limit angular $q promise concurrency?

How do I do something like $q.all but limiting how many promises are executed concurrently? My question is just like How can I limit Q promise concurrency? I want no more than 5 process spawned at a time The accepted answer for that other question…
Daryn
  • 4,791
  • 4
  • 39
  • 52
5
votes
3 answers

AngularJS deferred.reject not working but $q.reject working

I am confused between Angular JS deferred and $q. I found this SO Question that explains the difference between $q.defer() and $q.It explains $q.reject is a shortcut to create a deferred and then reject it immediately So $q.reject() must be equal…
Vishnu Sureshkumar
  • 2,246
  • 6
  • 35
  • 52
5
votes
0 answers

$timeout.flush TypeError: Cannot read property '$$nextSibling' of undefined

I have a segment of code inside a $timeout which executes a promise. When i write the unit test for that i use $timeout.flush() and i can go inside the $timeout block. The promise is then resolved (since $timeout calls $scope.$apply() internally)…
Andrew
  • 113
  • 1
  • 9
5
votes
2 answers

Use promise in directive for dynamic templateUrl

I have a promise SharedData which return a variable service .template as well. The value is mytemplate with which I build an url that I ant to pass to templateUrl directive but without success. app.directive('getLayout', function(SharedData) { var…
Greg
  • 473
  • 1
  • 5
  • 19
5
votes
2 answers

Promise chaining and dealing with an action not returning anything down the chain of promises

I have a question regarding Javascript promise chaining. Say I have an action somewhere down a chain of promise. That action does not return any value but it must complete before the chain can proceed. Do I need to wrap that action in a promise? Do…
balteo
  • 23,602
  • 63
  • 219
  • 412