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

How to wait for a function to finish its execution in angular 2.?

Below is my code, I want login() and authenticated() functions to wait for getProfile() function to finish its execution. I tried several ways like promise etc. but I couldn't implement it. Please suggest me the solution. import { Injectable } …
Raj Bhatia
  • 1,049
  • 4
  • 18
  • 37
6
votes
3 answers

How to make a WAR file from angular 2 (angular-cli) project?

I want to make a war file to deploy the angular2 project in an apache tomcat server. I made a maven project and inserted the angular2 project inside it. Then I made the webapp folder(instead of the dist folder in the angular2 project) in the…
Dulanjaya Tennekoon
  • 2,408
  • 1
  • 18
  • 31
6
votes
1 answer

Jasmine test for Angular service does not resolve deferred call

I'm pretty new to Angular and I am working to test an Angular service that runs off an API level service which wraps a bunch of calls to a REST service. Because it is working with HTTP requests, both parts of the service are working with promises…
glenatron
  • 11,018
  • 13
  • 64
  • 112
6
votes
2 answers

Why are Callbacks from Promise `.then` Methods an Anti-Pattern

I have seen answers on StackOverflow where people suggest furnishing a callback function to an AngularJS service. app.controller('tokenCtrl', function($scope, tokenService) { tokenService.getTokens(function callbackFn(tokens) { …
georgeawg
  • 48,608
  • 13
  • 72
  • 95
6
votes
4 answers

return a boolean after promise has been resolved/rejected?

I have a function that works absolutely fine. I just want to return true or false depending on the promise. //I want this function to return a simple true or false!!! function isAppOnline() { var is_connected =…
HIRA THAKUR
  • 17,189
  • 14
  • 56
  • 87
6
votes
6 answers

How to return single promise after for loop (which produces a promise on every iteration) is complete?

I have a problem with my promise return code, I have a function getTagQuotes which contains a for loop which can make multiple calls an API to return data into an array. How my code for this begins below: // If there are tags, then wait for promise…
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
6
votes
1 answer

AngularJS Array of Promises

Can anyone help me with some Angular promises? I have the following functions that should take in an array of file objects, iterate over them, and upload each one. During each iteration, a promise object is pushed to an array of promises. Within my…
Daniel Bonnell
  • 4,817
  • 9
  • 48
  • 88
6
votes
1 answer

Optional first promise in Angular chain

I have 2 $http calls that return promises but the first one is optional. I believe that I have to first create a promise using $q.defer() but I am missing something. Here's my non working attempt: var p = $q.defer(); if (condition) { p =…
cyberwombat
  • 38,105
  • 35
  • 175
  • 251
6
votes
2 answers

What is the difference between $http and $q?

a) What are the difference between $http and $q ? b) When should $q be implement over $http and vice versa ? c) When and best practice for implement $http and $q at the same time?
J Rod
  • 621
  • 1
  • 8
  • 14
6
votes
3 answers

q.all not working for multiple promises

I have the following q.all calling to resolve two promises. I checked all the posts and tried all other ways of implementation q.all and its the same case var xyzdeffered =…
Monish Das
  • 383
  • 2
  • 12
  • 28
6
votes
3 answers

Conditional Chaining of $http-calls with Promises in AngularJS

I have to execute three different $http-calls sequentially which depend on each other. Until now my working solution is something like this: $http.get(".../1/...").success(function() { $http.get(".../2/...").success(function() { …
Julian Habekost
  • 262
  • 1
  • 4
  • 17
6
votes
2 answers

Angular conditional promises

For an angular project, I have to nest promises and I run into cases where I am not sure of what I am doing. Here is one of my code : return Action1().then(function (data) { var defer = $q.defer(); if (data.condition) { …
JeromeModi
  • 117
  • 1
  • 7
6
votes
2 answers

Need to resolve a $http request before the execution of the resolve property inside $stateProvider

I’m building an angular application that is going to run on several domains. Since there are different configurations on each domain I'll need to fetch all the variables by doing a call to the server. The call will return a JSON object that contains…
Christian
  • 819
  • 1
  • 8
  • 23
6
votes
1 answer

Angular $q.reject().success(), does that make sense?

I'm reading a book called MEAN Machine, and as I'm getting to the late chapters, I've got stuck at one of the sample applications, that doesn't seem to work. The problem seems to occur because my mainController calls authService's Auth.getUser()…
Charles
  • 1,118
  • 13
  • 23
6
votes
1 answer

Angular logs error to console before raising promise.catch

I feel like I am going a little crazy, but Angular appears to throw an error for a promise even if I have a catch defined. It throws the error to the console, then allows the catch to run. Here is a super-simple fiddle The test code: $q.when(1) …
Kyeotic
  • 19,697
  • 10
  • 71
  • 128