Questions tagged [angular-promise]

Angular's $q promises provide a powerful abstraction over flow control. If you tag your question with this tag, consider also tagging it with "promise" tag. This tag is also appropriate for questions about angular and promises not relaying to $q directly.

0
votes
0answers
25 views

From Promise to Array (Javascript) [duplicate]

it is somehow possible to assign promise result to array that will be used further in the application. I'm able to print to response from server but without chance of assigning the result to variable: ...
0
votes
3answers
67 views

How to wait until 2 $http requests end in angularjs

I need to process responses of two different $http requests. What is the best way to do so, knowing that I have to wait for answers of both request before to process their results. I think I must use ...
0
votes
1answer
59 views

Angular - Promise: how to synchronise functions

I am using angular1 and I have 4 functions that need to execute synchronously. Assume those functions are : f1 , f2, f3 , f4 and need to run in that order. f1, f2, f3, f4 are functions that are used ...
0
votes
0answers
40 views

Return promise from Angularjs webapi

Using Angularjs here: I have a form where user fills up some data and clicks save button to save data : $scope.save = function (isValid) { if (isValid) { if (!$scope....
3
votes
1answer
39 views

Return string from promise result

I want to have an wrapper function arround this $translate service: https://angular-translate.github.io/docs/#/guide/03_using-translate-service so we can use those function easily in our code by ...
0
votes
2answers
30 views

potentially refactor code to use chained promises

The following code works fine but it seems like there should be a more concise way to write it. I have looked for examples of chained promises but haven't found anything close enough to this logic to ...
-2
votes
0answers
35 views

Promise is ignored! What is the best practice?

I am getting some hint from the IDE for some function that is saying "Promise returned from xxxx is ignored". Is it safe to ignore a promise if we don't need it ? What is the best practice?
0
votes
1answer
40 views

How do I return a different Promise only if first Promise errors out?

The specific situation is: I'm using a local storage API that returns a promise when you try to 'get' the value. The value I'm trying to get is a custom "UserProfile" object. If the value is not ...
3
votes
1answer
60 views

Why does async/await break $http.get/the angular digest cycle?

Have a look at the following Angular 1.x controller: class RootController { constructor($http) { this.variable = "apples"; // this.test($http); -- this works // ...
1
vote
1answer
39 views

Expect() not doing the comparison when using BDD

I am working with Protractor 5.4.0 and cucumber. The protractor.conf.js file is: global.expect = require('chai').expect; var chai = require('chai'); var chaiAsPromised = require('chai-as-promised'); ...
0
votes
1answer
53 views

element.getText().then(function) not being executed

I am working with protractor and cucumber. I want to print the text returned from getText. I am using .then function to obtain such text, but for some reason, console.log code is not being executed. ...
0
votes
2answers
40 views

Compare angular grid column cell texts against a string array using typescript

I am new to typescript and looking to scrape a list of values from an ag-grid column and compare it against a string array. Here is the function I wrote to achieve that. But my ActualRatingsValues....
0
votes
1answer
25 views

How get an object data in controller from a factory that fetch data with api in angularjs

I have a controller with two functions that both of them call me a function in factory : .controller("Ctrl",function($scope,fetchDataFromServer){ $scope.dataArray = []; $scope.dataArray2 = []; ...
0
votes
0answers
33 views

Firestore transaction produces console error: FAILED_PRECONDITION: the stored version does not match the required base version

I have written a bit of code that allows a user to upvote / downvote recipes in a manner similar to Reddit. Each individual vote is stored in a Firestore collection named votes, with a structure like ...
0
votes
0answers
9 views

Debugging $promise.then(…).catch(…)

I was debugging an angularjs code in google chrome debugger. The structure of the code is following : if (abc) { def.ghi({ id: vm.ProjectId }) ...
1
vote
1answer
102 views

Error: StaticInjectorError(AppModule) in angular 4 or angular 6

this is my app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { ...
0
votes
0answers
24 views

Angular promise is not working in firefox but working in chrome

I have following code this.getHomePageData = function(pageId) { var promise = $http({ "url": config.api.homePage + "/" + pageId, "method": "GET", "headers": { ...
0
votes
1answer
28 views

Use of promise after return from service Angular 5

In Angular app, I have created a "config.json" in assets folder where I have stored some settings regarding App to use further. json data in config.json is { "config":{ "worker_url":"http//:...
0
votes
0answers
50 views

AngularJS to Angular6 redirect

I have some AngularJS logic which redirects old urls to new format e.g var app = angular.module('app', ['ngRoute']); app.config(function ($routeProvider) { $routeProvider .when('/oldUrl;id=:id',{...
1
vote
1answer
143 views

How to consume a RESTful API with pagination to fetch all records sequentially in AngularJS

The API I am consuming provides with the link headers as such: </resource?page=1&limit=10>; rel="next", </resource?page=1&limit=10>; rel="last", </resource?page=0&limit=10&...
2
votes
2answers
53 views

call the same http request if it fails but with different parameter to get default data

does it make sense to call the same http request call within the catch if the first one fails but with different parameter in order to return some default data ? var defaultData = false; ...
2
votes
1answer
43 views

How to refactor chained $http calls and library call with callback

I have code resembling the following snippet: $http({ method: "GET", url: "/path/to/route?id=" + id }) .then(function (response) { var data = response.data; var summary = service....
0
votes
0answers
49 views

Manually cancel $q angularjs

I'm using angularjs version 1.7.2 for my project. In my project, I have some promises that needs managing and cancelling when the data change. Let say, I have a select tag with some options : <...
-1
votes
1answer
85 views

How to work around an early async return while getting AngularJS to wait before updating the UI?

I have a function that reloads the list of items on a dashboard that looks like the below snippet: // Code goes here angular .module('example', []) .directive('list', list) var fooCount ...
1
vote
1answer
53 views

returning array after promises within loop

I am trying to aggregate the responses after running a loop and having promises being called each time. However, the function does not wait for all the promises to be done and returns undefined. ...
0
votes
1answer
66 views

Why is my Observable never Resolved?

I am a newbie in javascript and I was going through Angular 2 Documentation and just happen to see that you can replace Promises with Observable. I have a very simple code and I don't know why i am ...
1
vote
1answer
47 views

AngularJS - Script stops running at factory function with promise return

I've been learning/working on a newbie project which is basicly a simple task manager(similiar to those todo list projects). And I designed a user login page for this project and here is how it works. ...
2
votes
2answers
45 views

AngularJS two http get in one controller make problems

i have two http GET in one controller and sometimes it works and two of them are working. sometime only one http Get is work. and sometimes none of them is shown. any suggestions? }).controller("...
1
vote
2answers
68 views

How do I make a promise resolve as an object in the view?

I'm trying to wrap a third party library to return an object that resolves into an object that can be displayed in the view, similar to how $resource() works. I'm aware that I can manually do .then() ...
-2
votes
2answers
55 views

$q.all not waiting for promise array to return/reject

I'm kind of at a loss here because from what I am reading in the documentation, this should be working properly. I have a potential of 3 forms that need to be saved. The 3rd one needs to wait for ...
0
votes
2answers
95 views

How to pause code till .then function is executed in AngularJS

While I am loading an AngularJS file my code is getting executed completely before the code in .then function completes its execution. How to pause code till the code in .then function executes. I ...
0
votes
1answer
38 views

NGRX call server just at the end

In my Angular application I have an effect (handled when the application starts) that retrieve the available langs from the server. I'm going to save the lang[] inside an object (GlobalData) saved in ...
0
votes
2answers
56 views

How to resolve promise inside Angular $timeout

With callbacks, I wrap the callback in an Angular $timeout block so that it updates the UI. function makeServerRequest(callback) { $timeout(callback); } makeServerRequest((response) => { $...
0
votes
0answers
44 views

How to read Json and pass its properties to page method that returns promise using protractor

I need help on iterating Json through for loop using protractor: Context of my issue: I have a method that returns Json response of REST Service. The response is handled in another method and ...
0
votes
0answers
19 views

AngularJS: Ajax Call does not send data

Using Angular 1.4.9 in a chained promise instruction, I am trying to send JSON data via AJAX request to a Node.js server. My problem: Node.js always receives an EMPTY request by the client and I can't ...
2
votes
4answers
53 views

How to check if both http calls fail?

I want to make 2 http post calls, and show an error if both calls fail, if one of the calls return data, then I don't want to show the error. this.http.post<any[]>(URL, jsonBody1, postJson) //...
2
votes
3answers
112 views

Pushing result from promise into array

I am trying to empty, then repopulate an array with the value returned from a promise. However when I do this it doesn't always add them back in the same order. $scope.$watch ('timeRange', function (...
-1
votes
1answer
42 views

Promises not coming back with AngularJS

Can someone explain to me why my function getAllBranchesAndAllTheirBranchChildren called by service costsBranchService doesn't come back when promise is resolved ? Is it because it is nested in ...
0
votes
1answer
28 views

Correct way of catching error in Promise objects

Ok so I am newbie in Angularjs,one of my current task is to code a CRUD functionality and I used the Promise to handle it. dao.updateEntityCharSpecUseRelSql = function (paramField) { return new ...
0
votes
1answer
31 views

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 ...
0
votes
1answer
30 views

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 ...
0
votes
0answers
18 views

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

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 ...
0
votes
1answer
59 views

Can I stop forEach until I get data from server with promise-then?

I'm trying to get img url from server using promise-then, and to update other object with that img url in server. However, I can't update data because function which is for updating data triggers ...
1
vote
1answer
47 views

AngularFire V1.2 $firebaseArray() $loaded() only called once [duplicate]

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 ...
0
votes
2answers
171 views

Angular 2 : View doesn't update when function is called from promise

My angular is pretty basic. I have a view where I display an object (which is in a service): <div *ngFor="let group of service.groups"> {{group.id}} - {{group.name}} </div> The ...
0
votes
0answers
48 views

Angular 5: custom async validator freezes browsers

I've a custom async validator that freezes my app. Tested in Chrome and Firefox. It happens after typing approx. 30 chars, which means the Validator was called approx. 30 times. Looks like the ...
0
votes
1answer
36 views

typescript casting return from database to class

I'm trying to return array of specific type from my provider in an ionic app using ionic 3.20.0 (Angular 5.2.10 && typescript ~2.6.2) In my provider I have this export class vwOrderList { ...
0
votes
1answer
51 views

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 ...
1
vote
3answers
74 views

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 ...
1
vote
2answers
35 views

AngularJS Promise best practise for chaining $q.all

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 ...