Search Posts

Category: angular-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. […]

Calling $http inside angularjs watch from a directive

I am trying to call $http service from inside a watch in my directive. Assuming, the directive is put on more than one input element. If the value of all elements changes together, the watches fire back to back and $http gets called back to back as well, sometimes messing up the response for each $http call, i.e for consecutive $http calls, even though the inputs are different response comes the same. What is the […]

Karma-Jasmine async test returns Error: Timeout – Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL [duplicate]

This question already has an answer here: Unit testing an asynchronous service in angularjs 2 answers I am currently writting tests for one of my AngularJS services in which I have async methods. In my Jasmine test the method is correctly called but I can’t retrieve the promise and I get the following error message : Error: Timeout – Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. I’ve tested to change the timeout […]

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 […]

Firebase $loaded() on $firebaseArray()

I am using AngularFire and promises on arrays ($loaded() on firebaseArray()). Currently, I’m using the following code: Problem: I go to page1, the data is loaded and all fine. Go to page 2 and come back to page1. Now the $loaded() doesn’t work until I do a full page refresh. How do I fix this problem? app.factory(‘Items’, [‘FBURL’, ‘$firebaseArray’, function(FBURL, $firebaseArray) { return { ofCategory: function(catId){ var ref = new Firebase(FBURL); var refSearch = new […]

AngularJS with $q data lost when chaining promises

In the following code I want to execute a series of $http requests that modify a list. When all the responses are received, I want to process the list and remove part of the content. The problem is that when I print the list after $q.all, the Chrome console shows a length of 3, but when I expand it to read the content only 2 elements are shown. On JSFiddle I have no issues, though. […]

Is there a way to flatten this promise chain more effectively (involves chaining on catch)?

Assume a function returning a custom promise. For the sake of this example, lets just assume a custom promise is needed: (Note: the environment is AngularJS [i.e. 1.x] that does ES5) function doMyFunction() { var d = $q.defer(); do1() .then (function () { return do2(); }) //P1 .then (function () { return do3(); }) // P2 .then {function () {console.log (“All good”); d.resolve(true); return d.promise;}) // P3 .catch (function () { console.log (“Oh no”); fallback1() […]

AngularJS Promise best practise

I’m new to writing and using promises and I’d like some advice. I have to chain my promises because some functions can only be run after others. I did used to handle this with a LOT of callback functions, which looked very messy and confusing. But with the chaining I’m doing… it’s starting to look a bit messy again and I’m wondering whether I’m doing this correctly… function calcNetPriceSaleCharge(theItem) { var setInitialChargeAmount = miscSaleSvc.getInitialCharge(theItem); var […]

create xlsx file from BLOB ancread add to ZIP, create ZIP in Angular JS

I am new in Angular Js, I am using angular Js 1.5 , My requirement is create xlsx file from BLOB and add XLSX file in ZIP and download ZIP folder on client side, I want to do this process on client side after getting BLOB from server, var b = new Blob([reportData], { type: “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet” }); I am create BLOB object like this , now my question is how convert this BLOB into XLSX […]

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 […]

Next Page »