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
12
votes
3 answers

AngularJS $http call in a Service, return resolved data, not promises

I want to know if it is possible to make a service call that uses $http so it returns data directly without returning a promise? I have tried to use the $q and defer without any luck. Here is what I mean: I have a…
iQ.
  • 3,811
  • 6
  • 38
  • 57
12
votes
2 answers

Injecting a resolved promise into service

I need to get some information (a schema) from the server before I set up a bunch of services that depend on that information. My server provides a schema that defines various properties of a model. In my angular code, I have a service that gets…
user2463201
  • 715
  • 2
  • 7
  • 11
11
votes
1 answer

Angular 6 Async-await not working on http request

Hi im using angular 6 to call a rest api with the code below. I am trying to acheive making the code synchronous with the async-await function. however something is missing async save() { if (this.changedRecords.length !== 0) { …
Joshua Vandenbor
  • 509
  • 3
  • 6
  • 19
11
votes
4 answers

Javascript: How to iterate on array using promises?

LIVE DEMO Given the following function: function isGood(number) { var defer = $q.defer(); $timeout(function() { if () { defer.resolve(); } else { defer.reject(); } }, 100); return…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
11
votes
2 answers

AngularJs console.log "$q is not defined"

I am getting this error in the console $q is not defined. When I did some research I found some thing like .q library has been deprecated from http://www.breezejs.com/documentation/breeze-labs/breezeangularqjs If this is so, then the whole concept…
RONE
  • 5,415
  • 9
  • 42
  • 71
10
votes
3 answers

Finally gets called immediately before promise gets fulfilled

I'm trying to execute a check once promise gets fulfilled in angularjs. request.then(function(res){ $ionicLoading.hide(); deferred.resolve(res); }, function(res){ $ionicLoading.hide(); deferred.reject(res); …
Indyarocks
  • 643
  • 1
  • 6
  • 26
10
votes
3 answers

AngularJS promise

AngularJS docs say: $q promises are recognized by the templating engine in angular, which means that in templates you can treat promises attached to a scope as if they were the resulting values. So could someone please explain the reason this…
Raman Chodźka
  • 558
  • 1
  • 7
  • 16
9
votes
2 answers

Angular 8 - How to use Promises and Async/Await

I keep trying to use tutorials but can't seem to figure out how to use Promises or async await. I have an http GET request and I want to wait for the result from the API before returning. The coming back as null because the function returns…
Justiciar
  • 356
  • 1
  • 3
  • 20
9
votes
2 answers

What is the difference between $promise and $q promises in angular1.x?

I started using promises in angular for resolving my api calls with the following syntax: $scope.module = moduleFactory.get({id: $stateParams.id}) .$promise.then(function(response){ $scope.module = response; } Now, I have…
9
votes
3 answers

AngularJS then() behaves differently than success()-error()

As the success() and error() functions are deprecated in AngularJS, I am updating my codes, replacing them with then(). Now according to my understanding, these two pieces of codes should behave identically: $http .get(/* some params */) …
Behrooz
  • 1,895
  • 4
  • 31
  • 47
9
votes
4 answers

Break out of a Promise "then" chain with errorCallback

-- EDIT -- I encountered a weird thing recently about promises, but I guess it's maybe because it's against the philosophy of promises. Considering the following code : // Assuming Auth is just a simple lib doing http requests with…
darkylmnx
  • 1,891
  • 4
  • 22
  • 36
9
votes
1 answer

Global Error handler that only catches "unhandled" promises

I have a global error handler for my angular app which is written as an $http interceptor, but I'd like to take it a step further. What I'd like is for each $http call that fails (is rejected), any "chained" consumers of the promise should first…
Steven M
  • 574
  • 3
  • 18
9
votes
1 answer

$rootScope.digest not completing a promise in Jasmine

We currently are trying to test our angular services which use promises to return values to the controllers. The issue is that the functions we attach to the .then do not get called in Jasmine. We found that adding $rootScope.digest() to the…
BrendanM
  • 383
  • 3
  • 14
9
votes
2 answers

Angularjs, wait for a nested promise

I have 3 services that return 3 promises, but the third needs the data from the second, so I call it inside the second. I want to wait for all the three promises to be solved, this is the way that I implemented, but doesn't work (waits only for the…
Tres
  • 571
  • 1
  • 5
  • 19
9
votes
1 answer

AngularJS : Pass additional parameters to chained promises

I want to chain some promises that are returned by services. This works, as long as some of the methods that return the promises, doesn't require additional parameters. This is my example: var first = function() { var d = $q.defer(); …
23tux
  • 14,104
  • 15
  • 88
  • 187