angular-promise

angular $http / jquery complete equivalent

送分小仙女□ 提交于 2019-12-01 15:15:13
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 this: $http.get(someUrl).success(function(){ successCode(); completeCode(); }).error(function(){ errorCode(); completeCode(); }) but I would rather write something like: $http.get(someUrl).success(function(){ successCode(); }).error(function(){ errorCode(); }).complete(function(){ completeCode(); }) I've tried also using the promise API but I end up having the same problem. Any

Angular Promises and Chaining: How to break a chain if it has business data errors

怎甘沉沦 提交于 2019-12-01 12:17:34
I thought that I had this all figured out on previous projects through the years.. Apparently not. Goal : Take Service that calls other Services and if there is any type of error being returned ( not a status of 200 ) then I need the async thing to be waiting and not proceeding. Seems to me like I don't ever see really that great of examples as it is all very simplistic. I read various articles about what Angular (1) is doing under the hood , and i see that there are $q, .then, .success etc.. Seems that I am having issues with return and with other nested and bundled service calls being made

Angular Promises and Chaining: How to break a chain if it has business data errors

旧城冷巷雨未停 提交于 2019-12-01 11:55:15
问题 I thought that I had this all figured out on previous projects through the years.. Apparently not. Goal : Take Service that calls other Services and if there is any type of error being returned ( not a status of 200 ) then I need the async thing to be waiting and not proceeding. Seems to me like I don't ever see really that great of examples as it is all very simplistic. I read various articles about what Angular (1) is doing under the hood , and i see that there are $q, .then, .success etc..

How to stop/break in the middle of chained promises

大城市里の小女人 提交于 2019-12-01 09:23:30
I have a chain of $http calls to server. If one call fails I want to display notification to user and stop the chain. At first I thought I can use the $q.reject to stop the chain, but it turned out the program flow continues to the next then 's error handler. I have also tried returning nothing, but the flow still continues. Can I stop the flow mid chain? So for example the script below should print result: |A|D|F instead of result: |A|D|F|E|H|J . If the flow cannot be stopped mid chain, must I add extra condition in each then 's error handler, or is there more elegant way? angular.module(

Are Angular's promises asynchronous?

半城伤御伤魂 提交于 2019-12-01 08:32:48
问题 I may have miss something about Angular's promises but I was wondering something : are promises asynchronous ? I'm not sure if 'asynchronous' is the right word but let me explain myself. In my code I use promises to do a really big process (read and write hundreds of big files) while I display a loading bar to watch the progress of the process. I've noticed that even if my code is in a promise, it seems to not really be asynchronous and freeze the display (that I assume is manage by the main

Javascript: How to iterate on array using promises?

早过忘川 提交于 2019-12-01 03:26:32
LIVE DEMO Given the following function: function isGood(number) { var defer = $q.defer(); $timeout(function() { if (<some condition on number>) { defer.resolve(); } else { defer.reject(); } }, 100); return defer.promise; } and an array of numbers (e.g. [3, 9, 17, 26, 89] ), I would like to find the first "good" number. I would like to be able to do this: var arr = [3, 9, 17, 26, 89]; findGoodNumber(arr).then(function(goodNumber) { console.log('Good number found: ' + goodNumber); }, function() { console.log('No good numbers found'); }); Here is one possible recursive version to implement this:

What's the equivalent of Angular's $q in Angular2?

廉价感情. 提交于 2019-12-01 02:14:21
What's the equivalent of Angular's $q in Angular2? Specifically, I'm looking for $q.when , which allowed you to do something like: return $q.when(['TestResponse']); Günter Zöchbauer new Promise((resolve, reject) => { if(xxx) { resolve('ok'); } else { reject('error'); } }).then(x => doSomething()) See also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise or http://learnangular2.com/es6/promises You can use the native es6 Promise. One of the main reason to make new angular is es6 and nearly comming es7. 来源: https://stackoverflow.com/questions/37719306

What's the equivalent of Angular's $q in Angular2?

∥☆過路亽.° 提交于 2019-11-30 21:42:28
问题 What's the equivalent of Angular's $q in Angular2? Specifically, I'm looking for $q.when , which allowed you to do something like: return $q.when(['TestResponse']); 回答1: new Promise((resolve, reject) => { if(xxx) { resolve('ok'); } else { reject('error'); } }).then(x => doSomething()) See also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise or http://learnangular2.com/es6/promises 回答2: You can use the native es6 Promise. One of the main reason to make

Angular $q returning promise multiple $http calls

跟風遠走 提交于 2019-11-30 20:38:42
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 $http({ method: 'GET', url: '/api/' + api }) .then(sendResponseData) .catch (sendGetVolunteerError); } The current function I have loops over each api and pushes each object in the api into an array and then pushes it into an overall array. I had this functioning, returning an multi-dimensional array, which needed to be flattened out. I'd like to return

Chain Angular $http calls properly?

被刻印的时光 ゝ 提交于 2019-11-30 17:16:27
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 "no data", if it succeeds and says a call can be made, the second call is made, if not - "no data" again. If the second call succeeds, it returns data, if not - "no data". It looks like this (approximately, I simplified for general idea, so don't worry about the minor mistakes here): return $http.get (something) .then(function(allowedAccess){ if