Search Posts

Category: q

AngularJS 1.6.5: Is it possible to catch $q unhandled errors with $exceptionHandler?

Is there a generic solution to catch all unhandled errors in $q with $exceptionHandler in angularJS 1.6.5? I have code like this: this.$http.get(…) .then(…) .catch(error => { switch(error.message){ case …: case …: default: throw error; <– this is silently ignored without passing to $exceptionHandler } }); I’m supressing ‘Unhandled rejection warning’ ($qProvider.errorOnUnhandledRejections(false);), but it shouldn’t matter, as I get it. Source: AngularJS

Angular $resources Cancel requests : $q

how to Angular $resources Cancel requests : $q I’m trying to understand… How can I implement a requests cancell for this kind of services. I was reading, that I shoud use $q.defer() angular.module(‘App’).service(‘TService’, function ($resource, portal) { return $resource(portal.getUrlServer() + ‘api/T/:id’, { id: ‘@Id’ }, { T_GET: { method: ‘GET’, params:{ id_turno: ‘@id_turno’, }, url: portal.getUrlServer() + ‘api/T/T_GET/’ }, G_GET_Turno: { method: ‘GET’, params: { id_tramite_relevado : ‘@Id_Tramite_Relevado’ }, url: portal.getUrlServer() + ‘api/T/G_GET_Turno/’ }, }); […]

AngularJS: promise in a loop

I am unable to do the promise looping. I make a service call to get list of providers, then for each provider, I make another service call to get a customer. A provider has 1 or more customers. So eventual list of customer is to be decorated and displayed. In other format I am trying to achieve: *serviceA.getProvider(){ –foreah(providers){ —foreach(provider.customerID){ —-serviceB.getCustomer(customerId) —} –} } .then( –foreach(Customer){ —updateTheCustomer; —addUpdatedCustomerToAList –} displayUpdatedCustomreList(); )* I have written following […]

Automating promises in a service

I have some very inefficient code in a service that I would like to streamline. var dayPromise = DayResource.query({ start: dateQueryParam, end: dateQueryParam }).$promise.then(function(response) { if (response.length) { response = response[0]; MealLogResource.query({ … }, function(mealLog) { mealLogDeferred.resolve(mealLog); }); … … … } var dayBack1Promise = DayResource.query({ start: dateQueryParamBack1, end: dateQueryParamBack1 }).$promise.then(function(response) { if (response.length) { response = response[0]; MealLogResource.query({ … }, function(mealLog) { mealLogDeferredBack1.resolve(mealLog); }); } else { // Instantiating new empty day response = […]

Showing dynamic content inside ngRepeat

Struggling to show dynamic content inside a ngRepeat. When it comes time to show my promise content, I’m getting an empty object {}: <div ng-controller=”DemoCtrl”> <div class=”sidebar” ng-repeat=”row in rows”> <div class=”row”> <input type=”checkbox”> <div class=”name”>{{}}</div> <div class=”title”>{{map[$index]}}</div> </div> </div> </div> and the controller: function DemoCtrl($scope, $http, $q) { const rows = function() { const rows = []; for (let i = 0; i < 12; i++) { rows.push({ id: `demo-${i}`, name: `Demo ${i}` }); […]

Angularjs ngresource getting peoblems for promise and resolve

I have a controller and there I call a service. var rowCollection=[];‘getAllcarList’).getAllcarList({}).$promise.then(function(data) { rowCollection.push(; }); console.log(rowCollection); After the service call If i want to use the rowCollection it shows undefined as the response till not come.How to stop execution until response come. So that the variable can use any where in the program. In my service I have code like this function($resource) { var apiResourceUrl=’’; var factory = {}; factory.allCars= function(queryType) { var hsRESTUri […]

Why does a failed assertion trigger a promise catch?

While writing unit tests for an angular app I was experiencing unexpected results. I was able to condense the unexpected behavior into a sample test. The should.equal(true, false, ‘should then’) assertion failure in the then block seems to trigger the catch block of the promise. describe.only(‘test’, function () { var $q, $rootScope; beforeEach(function () { inject(function(_$q_, _$rootScope_) { $q = _$q_; $rootScope = _$rootScope_.$new(); }); }); var stubService = sinon.stub(service, ‘getPanel’); it(‘shall…’, function() { //1 […]

loop until promise function give result

I’m looking to loop on a promise function until I have the result I want. As of now I’m using recursivity like this: function pull() { dataFactory.pullFunction().then(function(res) { pull() }) } But that’s giving me some front-end/style bugs for my loading bar for example. I would do something like this: function pull() { while (res.status == ‘ONGOING’) { dataFactory.pullFunction().then(function(res) { // my stuffs }) } } But when I try it the pullFunction() is never […]