Search Posts

Category: promise

Angular success function called before http.get function returns

I have an angular controller which makes an HTTP GET request and on the promise return, calls either a success of error function. My code right now will sometimes execute the success function after the GET request returns and sometime execute before it. Is there something I’m messing up in my promise handling? Something to note, sometimes the http GET doesn’t even get called (or at least its breakpoint) and the success function happens regardless. […]

Worker JS only return promise one time

I’m trying to implement a worker. I have an Angular JS application and the factory calls the worker to update the frontend based on a json change. My worker is working correctly, it’s running every 20 seconds, but the first JSON change it works, so, it means, I have a promise (as worker answer) and the controller get the promise. But… the worker continue working, it gets the differences but the factory doesn’t return the […]

Cannot find function variable name in angularjs

I’ve created following AngularJS code, but I’ve found Error: Can’t find variable: modifyCustomerAgent error when I render call modifyCustomer() my code. Please let me know what’s wrong. Thanks. function modifyCustomer() { return modifyCustomerAgent(modifyCustomerData, true).then(function(data) { console.log(JSON.stringify(data)); }); } $scope.modifyCustomerAgent = (saveFormData, isUpgrade) => { return { property: ‘value’ }; } Source: AngularJS

Refresh data After CRUD in AngularJS & Express

Here is my problem: I’m doing CRUD to MySql database, and after the create, update or delete my data no refresh correctly. Below in this images I’ll try to explain the actual behaviour: I have a modal to do these operations, but when I return to my main controller, the data only refresh after a F5, although it sometimes works perfectly. I think I need a promise or callback (the response from node is asynchronous) […]

Stop a promise chain without using reject in AngularJS

According to this blog post, it’s possible to return null in a resolver function to skip over subsequent then handlers in a promise chain. I’m curious as to how this works — nothing in the Promises/A+ spec defines this behavior that I can see. For my use case, I adapted their example to handle rejections from the $uibModal modal dialog service in Angular UI Bootstrap, which resolves or rejects depending on whether the modal is […]

(Access-Control-Allow-Origin – CORS issue when fetching data from 2 URL for promises

So I have promises in AngularJS which fetch data from 2 URLs. promises.push(loadingJson(‘’)); promises.push(loadingJson(‘’)); $q.all(promises).then(function(resultList){ }, function(errList){ }); After running the page (using Promises) in web server, it gives error “Origin ‘’ not allowed by Access-Control-Allow-Origin.” and “XMLHttpRequest cannot load ‘1.json’ and ‘2.json’ due to access control checks”. For Jquery GET method I can use JSONP to solve the error. But is there a way that can solve it in angularJS promises? Source: AngularJS

Returning value from a promise [duplicate]

This question already has an answer here: How do I return the response from an asynchronous call? 33 answers I am working with angularjs and chrome app. (Beginner in this scope) I am using idb library of promise for indexedDB. What I want is to get the all categories from store and return them in a controller function. my code look //check for support if (!(‘indexedDB’ in window)) { console.log(‘This browser doesn’t support IndexedDB’); } […]

executing function after multiple angular.forEach [duplicate]

This question already has an answer here: How to wait till the end of $compile in angularJS 7 answers angular.forEach(values1, function(value, key){ $compile(value)($scope) }); angular.forEach(values2, function(value, key){ $compile(value)($scope) }); foo() I want to execute function foo() only after these two forEach complete. any help. I am just a beginner. Source: AngularJS

How to wait till the response comes from the $resource request, in angularjs?

I am going to tell you a bit about what I am doing so you may help me. I am reading some records from a .txt and for each record I need to make some verifications, in order to do this, I make a $resource call to my backend service to get the regex which will be use to verified each record. I need to wait for the response of the service. I have this […]

How to deal with nested promises in javascript angularJS

Function 2 is using Function 1 return while Function 3 uses both returns, how to do cleanly ? Function 3 is only returning me undefined values right nom. Here are my 3 functions. Function1 $scope.nombreCompetencesATraiter = function(){ var nbr = 0; notesService.getNotesByCollaborateurId($scope.idCollaborateurSelectionne).then(function(data){ $scope.myNotes = data; angular.forEach($scope.myNotes, function(valueNote, keyNote) { if ((valueNote.status === “EN_ATTENTE_DE_VALIDATION”) || (valueNote.status === “EN_ATTENTE_DE_SUPPRESSION”)){ nbr++; } }) console.log(nbr); return nbr; }) } Function 2 $scope.affinerConfigBoutonsCompetences = function() { nbCompetenceATraiter = $scope.nombreCompetencesATraiter(); if […]

Next Page »