angular-promise

How can I call the second sequential promise design pattern method in a loop in angularjs? [duplicate]

时间秒杀一切 提交于 2019-12-13 22:22:45
问题 This question already has answers here : JavaScript closure inside loops – simple practical example (44 answers) Closed 3 years ago . New to angularjs and trying out the promise pattern for the first time - I have a service utility inside which I have this method - this.getData= function(url){ var defer = $q.defer(); $http({method: 'GET', url: url}). success(function(data, status){ defer.resolve(data); }) .error(function(data, status) { defer.reject(status); }); return defer.promise; }; Now

Angular2: Object doesn't support this action in Microsoft Edge browser

丶灬走出姿态 提交于 2019-12-13 03:04:46
问题 My angular2 application throws exception stating Object doesn't support this action only in Microsoft edge. Please check the below image: I debugged and found out that the exception is thrown at promise then code. To be more specific, I am getting the error at then on below code: this.dataLayerService .postLogin(this.model, this.postURL) .then(usermasterResponse => this.setToken(usermasterResponse)) .catch(error => { this.toastCommunicationService.setMessage(error, "", this

Automatically apply $scope changes (trigger digest) after a non-$q promise resolves in angularjs

半世苍凉 提交于 2019-12-13 02:36:31
问题 Let's say you have: function myPromise() { // using some promise lib other than $q, like Q or bluebird var defer = Q.defer(); defer.resolve('John'); return defer.promise; } and then you have something like: function foo() { return myPromise().then(function (name) { return name + ' Smith'; }); } foo().then(function (name) { $scope.$apply(function () { // or can use $timeout console.log('after foo'); $scope.text = 'Hey ' + name; }); }); Is there a way to modify foo so that the after foo block

AngularJS validation and promises

*爱你&永不变心* 提交于 2019-12-13 02:26:35
问题 In an Angular app, form is validated via custom JS function before submitting. Based on a condition, I need to show a confirmation dialog to the user, wait for confirmation or rejection, then proceed with validation. I'm having difficulties with achieving this asynchronously. I believe I am not using the promise correctly, but not sure what needs to be updated. Factory app.factory("confirmDialogService", ['$q', 'ngDialog', function ($q, ngDialog ) { return { popConfirm: function () { var

Make function wait for $http response in AngularJS

*爱你&永不变心* 提交于 2019-12-13 00:27:45
问题 I have a method seatClicked() that calls getUserID() to get the user id corresponding to the session atribute 'user'. There is a table that contains the username and user id(unique). The following is the definition of seatClicked() $scope.seatClicked = function() { promise = $scope.getUserID(); promise.then(function(results){ $scope.seatID.userID = results; // store the user id in $scope.seatID.userID }); } This is the definition for getUserID() $scope.getUserID = function() { var deferred =

$q.defer() then of the then [duplicate]

拜拜、爱过 提交于 2019-12-12 22:01:32
问题 This question already has answers here : Chained promises not passing on rejection (3 answers) Closed 4 years ago . I didn't understand the behavior of the return value of then , Here its documentation - then(successCallback, errorCallback, notifyCallback) – regardless of when the promise was or will be resolved or rejected, then calls one of the success or error callbacks asynchronously as soon as the result is available. The callbacks are called with a single argument: the result or

wait for async function in loop to finish executing before next iteration

爱⌒轻易说出口 提交于 2019-12-12 13:29:34
问题 I have an array of image urls to download asynchronously. I need to wait the next iteration until the first async task completed. Here is my code snippet: downloadQueue.forEach(function (download, idex) { download.startAsync().then( function (res) { console.log('onSuccess'); }, function (err) { console.log('onError'); }, function (msg) { var progressPrecent = parseFloat(msg.bytesReceived / msg.totalBytesToReceive * 100).toFixed(2); console.log('Progress: ' + progressPrecent); }); }); After

Trouble with asynchronous events in angular

烈酒焚心 提交于 2019-12-12 13:07:17
问题 The code I have loops through 10 items in an array, makes a request for each item, then pushes the returned data to an array. Everything runs fine until the $q.all line. details.getDetails = function(idSet, pageNum) { var page = idSet[pageNum], mainDeferred = $q.defer(), promises = [], combinedItems = []; for(var i=0; i<page.length; i++){ var deferred = $q.defer(); ngGPlacesAPI.placeDetails({placeId: page[i][i]}) .then(function(data){ combinedItems.push(data); console.log(combinedItems); ///

Have multiple calls wait on the same promise in Angular

不打扰是莪最后的温柔 提交于 2019-12-12 11:21:08
问题 I have multiple controllers on a page that use the same service, for the sake of example we will call the service USER. The first time the USER.getUser() is called it does an $http request to GET data on the user. After the call is completed it stores the data in USER.data. If another call is made to USER.getUser() it checks if there is data in USER.data and if there is data it returns that instead of making the call. My problem is that the calls to USER.getUser() happen so quickly that USER

Consecutive writings to several files in the server

谁都会走 提交于 2019-12-12 05:53:25
问题 (* As my previous question has been more or less answered, and the code has evolved, I open a new question. *) I want to build a simple playground with MEAN stack that mimics plunker: we have a list of files and a textarea on the left hand, and a live preview on the right hand. Note that the files are saved in a temporary folder, and the live preview is an iframe injected by the files from that temporary folder. ********** what I have written ********** In the html file, I add one controller