Return an array from a function with a promise

I need to return the array lotSpecItems from this function once it is populated: public getLotSpecItems(id: number) { let toReturn = this.resourceClass.getLotSpecItems({ lotId: id }); let lotSpecItems = []; return toReturn.$promise.then(...
more »

2017-11-21 23:11 (1) Answers

How to mock chained promises using Jasmine?

I am writing a unit test to a method that contains this piece of code: Name.get($scope.nameId).then(function(name){ Return name; }).then(doSomething); The function doSomething(name) looks like this. function doSomething(name){ addNametoLi...
more »

2017-10-20 02:10 (2) Answers

Angularjs how to get filename extension?

Hi I am developing angularjs application. I am doing file upload module. I am trying to validate the files. I want to upload only xlsx or xls files. I have developed directive and factory method to upload files as below. myapp.directive('fileModel',...
more »

2017-07-18 10:07 (3) Answers

Promise Error in Observable not calling catch

I am using @angular/http for http calls (Observable) and NativeStorage library for storage mechanism which is Promise. That's why I use FromPromise to convert Promise funtion "NativeStorage.getItem("xxx")" to Observable. I am even not sure if this i...
more »

2017-07-01 18:07 (2) Answers

$q.all of AngularJS only works for one result

I am working on function that calculates a distance from a given object to a number of other places with the help of Google Distance Matrix which is of course async therefore I'm dealing with promises. When the number of places is one, everything wo...
more »

2017-06-08 16:06 (2) Answers

$q.all slower than sequential .then()?

I have some angular code that calls two separate backend services via $http.get. The backend is ASP.NET MVC 5. I call the services via $http.get, and since I need a response from both services before continuing, I wrap the returned promises in $
more »

2017-06-02 15:06 (1) Answers

Using $q with $http

In my $routeProvider I have a resolve property to get data from an API before I instantiate my controller. Why is it when I use the $q with the $http service, I can pass the data to my controller. Aren't they both doing the same thing? Here is my o...
more »

2017-04-09 04:04 (2) Answers

Angular Service Not Filtering Data

I am fetching the details from an API using Angular Service and I want to return only the matching items. Meaning, after I type some text, I will click a button, which will call a function in a Controller which will call the Service to get the detail...
more »

2017-04-04 17:04 (3) Answers

Angular $http.get: How to catch all the errors?

Im sending a form to nodejs for authentication. Using $http.get in the following function and adding a promise > .then. In production, does this handle all the errors that I may get from the server? Do I need to add anything else to this function? M...
more »

2017-03-24 00:03 (2) Answers

Wait for 1 promise and then all promises using $q

I'm fairly familiar with how $q works and I use it in angularjs to wait for single promises to resolve and multiple promises to resolve with $q.all(). The question is I'm not sure if its possible to do this (and if it works correctly): Can I wait fo...
more »

2017-02-07 14:02 (1) Answers

Node.js + Angular.js promises sync issue

I am working on a chat app which is Node.js + MongoDB (Mongoose library) on the server side, and Angular.js on the client side. I have a database collection (MongoDB) for rooms (all the rooms in the app), which looks like this: // ------- creating ...
more »

2016-12-31 16:12 (2) Answers

Possibly unhandled rejection in Angular 1.6

I have a code with AngularJS: service.doSomething() .then(function(result) { //do something with the result }); In AngularJS 1.5.9 when I have error in the .then() section like: service.doSomething() .then(function(result) { var...
more »

2016-12-22 11:12 (1) Answers

What is the HTTP promise object in AngularJS?

Although I am working with the HTTP promise object in AngularJS, I don't have a clear concept of what an HTTP promise object actually is and what the is difference between an HTTP promise object and a traditional object in AngularJS! Would anybody e...
more »

2016-11-20 15:11 (3) Answers

AngularJS - $q undefined in a directive

I'm trying to inject $q into my directive, but though $q is defined as a resolver() at first, when calling the function it is undefined. Maybe something related to binding? I don't know. (function () { 'use strict'; myForm.$inject = ["$q"]; angu...
more »

2016-09-14 13:09 (3) Answers

Chaining multiple promises, including Promise.all

I have a requirement which requires chaining of Promises. In my Ionic app, I need to iterate over a list of files and zip them. Then the zip needs to be stored on the device itself (iPhone in this case). I already have the list of files that need to...
more »

2016-09-10 16:09 (2) Answers