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

Testing Angular when mixing $q and ES6 promises

I am having a problem where my code mixes ES6 Promises with Angular promises, and it works in production by I cannot write unit tests that pass. This code snippet demonstrates two instances where Jasmine unit tests will fail, but the code works fine…
crunch
  • 675
  • 3
  • 8
7
votes
2 answers

Angular Js : '$q.defer is not a function' error

After Refering this Link , I am trying to get JSON data into my angular service. Service: .factory('restservice', ['$rootScope','$http', '$q', '$log', function($rootScope,$q, $http) { return { getData: function() { var defer =…
UzUmAkI_NaRuTo
  • 565
  • 3
  • 8
  • 20
7
votes
1 answer

AngularJS : Should service's boolean method return promise that resolves to true/false, or that gets resolved/rejected?

The patterns of promises usage still confuse me. For example, in Angular application, I have a service usersService with method emailExists(email). Obviously, it performs request to the server to check whether given email already exists. It feels…
Dmitry Frank
  • 10,417
  • 10
  • 64
  • 114
7
votes
1 answer

Resolving a promise in a service/factory vs in a controller with AngularJS

So I have played around with getting a promise to resolve in a service vs in a controller. I'd prefer to resolve it in the service so I can reuse the variable without having to resolve it multiple times. The problem I'm having is that it works, but…
Brooke Clonts
  • 465
  • 1
  • 10
  • 20
7
votes
2 answers

Difference between $q.when and $q.defer in angularJS

I am seeing angularJS files where in some places reviewer has commented these 3 lines: var deferred = $q.defer(); deferred.resolve(BrandList); return deferred.promise; and replaced with this one: return $q.when(BrandList); I would like to…
Devesh Agrawal
  • 8,982
  • 16
  • 82
  • 131
7
votes
3 answers

Angular $q returning promise multiple $http calls

I'm working on an $http call that loops over each of multiple api's and returns all of the data in one object. I usually have the promise ready to resolve when the $http call has been made. Similar to this: function getAllData(api) { return…
byrdr
  • 5,197
  • 12
  • 48
  • 78
7
votes
1 answer

$q.all and nested promises

Have a question about synchronizing nested promises when using $q in Angular. Will the following code ensure that the entire chain of promises is waited for? Meaning will the nested calls to services that return promises be waited for in the $q.all…
TGH
  • 38,769
  • 12
  • 102
  • 135
7
votes
2 answers

AngularJS : chaining promises over forEach loop

I'm having trouble wrapping my head around promises. I'm using the Google Earth API to do a 'tour' of addresses. A tour is just an animation that lasts about a minute, and when one completes, the next should start. Here's my function that does a…
Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
7
votes
4 answers

AngularJS $promise then() data undefined

I am trying to get data assigned to a $scope variable. Inside my $promise.then() function it is displaying correctly but outside the function it shows as undefined. The following is my controller…
7
votes
2 answers

AngularJS + $q, Do something after multiple ajax calls have finished

I need to load some data on page load and then do execute a task. in order to get the data i want i execute multiple different ajax calls. But in order to execute the task, i need all to make sure that all the ajax calls have finished. Here is what…
Christos Baziotis
  • 5,845
  • 16
  • 59
  • 80
7
votes
1 answer

Simplifying promises in Javascript

Are the following code snippets equivalent? Version 1 function doSomething() { var defer = $q.defer(); foo().then(function() { bar().then(function() { defer.resolve(); }); }); return defer.promise; } Version 2 function…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
6
votes
1 answer

How to wait for the last promise in a dynamic list of promises?

I have a function F that starts an asynchronous process X. The function returns a promise that is resolved when X ends (which I learn by means of a promise returned by X). While the (w.l.o.g.) first instance of X, X1, is running, there may be more…
O. R. Mapper
  • 20,083
  • 9
  • 69
  • 114
6
votes
1 answer

TypeScript generics: what if Promise reject and resolve types differ?

Simple and common Angular2+ data service that handles errors and uses Promises: // imports skipped class DataType {} class Error { constructor(error: HttpResponse) { this.error = error.json() } } @Injectable() export class…
6
votes
0 answers

Angular2 Tutorial: Promise error (type not assignable) in Service

I'm following the tutorial "Angular Tour of Heroes" at the Angular.io site. I've setup the project with Angular CLI (see environment versions at the end of this post). I'm stuck at point 5 (services) : using the same files provided by the tutorial,…
rodrunner
  • 1,860
  • 4
  • 23
  • 34
6
votes
3 answers

return a promise that resolves to a boolean true or false if a value is found

I need to make an api call that returns me a response of id's and values associated with it. The promise then resolves and returns a true or false if the id queried was found or not found. How can i achieve this? New to using promises. As is…
looneytunes
  • 741
  • 4
  • 16
  • 35