angular-promise

How to wait for AsyncRequests for each element from an array using reduce and promises

夙愿已清 提交于 2020-01-17 04:51:07
问题 I'm new on AngularJS and JavaScript. I am getting remote information for each of the elements of an array (cars) and creating a new array (interested prospects). So I need to sync the requests. I need the responses of each request to be added in the new array in the same order of the cars. I did it first in with a for: for (a in cars) { //async request .then(function () { //update the new array }); } This make all the requests but naturally didn't update the new array. After seeking in forums

Angular js promises chaining

…衆ロ難τιáo~ 提交于 2020-01-17 03:10:47
问题 Ive been trying to figure out promises for the last two days and i gotten this so far. Any guided direction would be great as i think i confused my self. So this is my service, it has to run in order with a timeout after image capture for the server to update: returnImage: function() { var results = {}; function getCameraDirectory(){ // Get directory infomation from camera var list = []; deferred = $q.defer(); console.log("getCameraDirectory"); $http.get(BASE_URL + IMAGE_URL).then( function

How can I limit angular $q promise concurrency?

£可爱£侵袭症+ 提交于 2020-01-13 10:12:13
问题 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 is a library written for promise wrapped to work with Q. But I'm interested specifically in a solution for Angular's $q rather than for Q . Background: The problem being solved: I have a bunch of files to download in 2 steps: a) Get URL b) download

How can I limit angular $q promise concurrency?

帅比萌擦擦* 提交于 2020-01-13 10:12:10
问题 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 is a library written for promise wrapped to work with Q. But I'm interested specifically in a solution for Angular's $q rather than for Q . Background: The problem being solved: I have a bunch of files to download in 2 steps: a) Get URL b) download

Setting a timeout for each promise within a promise.all

只愿长相守 提交于 2020-01-12 19:11:30
问题 I am able to successfully perform a Promise.all, and gracefully handle resolves and rejects. However, some promises complete within a few milliseconds, some can/could take a while. I want to be able to set a timeout for each promise within the Promise.all, so it can attempt to take a maximum of say 5seconds. getData() { var that = this; var tableUrls = ['http://table-one.com','http://table-two.com']; var spoonUrls = ['http://spoon-one.com','http://spoon-two.com']; var tablePromises = that

angular $http / jquery complete equivalent

旧城冷巷雨未停 提交于 2020-01-11 08:05:14
问题 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

How convert Angular promise to jquery deferred object

徘徊边缘 提交于 2020-01-11 04:43:06
问题 I want to return promises from my module/sdk to non-angular javascript. For example if I'm returning promise to a jquery, I should be probably sending jquery deferred object. How can I convert an Angular promise to a jquery promise/deferred obj. Any suggestions are much appreciated. 回答1: Disclaimer : jQuery promises don't play nice with other libraries - at all . jQuery will not assimilate other third party promises on its own. Angular $q promises on the other hand - will, so whenever you

AngularJS $promise then() data undefined

佐手、 提交于 2020-01-11 02:27:23
问题 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 code: angular.module('testSiteApp').controller('TestController', function ($scope, Tests) { $scope.test = Tests.get({id: 1}); $scope.test.$promise.then(function(data) { $scope.tasks = data.tasks; console.log($scope.tasks); }); console.log($scope.tasks); }); The results inside the then() function:

AngularJS $promise then() data undefined

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-11 02:27:06
问题 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 code: angular.module('testSiteApp').controller('TestController', function ($scope, Tests) { $scope.test = Tests.get({id: 1}); $scope.test.$promise.then(function(data) { $scope.tasks = data.tasks; console.log($scope.tasks); }); console.log($scope.tasks); }); The results inside the then() function:

AngularJS check if promise is empty or not

淺唱寂寞╮ 提交于 2020-01-07 09:35:11
问题 Hi I have this code for the purpose of checking if there are users in the database, if it finds shows a list of users on a view, otherwise shows a view with form of user creation, but didn't work the check expression what I'm doing wrong users = Users.query(); users.$promise.then( function (data) { if (!data) { $location.url('/NewUser') } else { $location.url('/UsersList') } }); 回答1: It is probably returning an empty array in case nothing is found. Try checking the data length. if (data