angular-promise

promise chaining vs promise.all

限于喜欢 提交于 2019-12-31 05:34:10
问题 i have a task to enter the notification date using protractor where i need to clear contents before entering so i have came up with this code this.Then(/^I should enter "Notification Date"$/, () => { const d = new Date(); return orderCheckOutPage.pageElements.recipientNotificationDateMonth.clear().then(() => { return orderCheckOutPage.pageElements.recipientNotificationDateMonth.sendKeys(d.getMonth() + 1).then(() => { return orderCheckOutPage.pageElements.recipientNotificationDateDay.clear()

How to use promise with two http requests

删除回忆录丶 提交于 2019-12-31 05:27:11
问题 I'm trying to make couple of HTTP requests, one inside another, and I'm having a trouble restructuring my JSON object. I have a factory function, first of all i'm trying to get all the teams, each team has an Id, and then i'm getting all the news for each team with the id related, and putting that news in the first JSON object. but this is not working ! .factory('teamsFactory', function ($http,CacheFactory,LocaleManager,$q) { teams.Getteams= function() { var zis=this; var promise=$http(

Response of Http Api call promise is undefined - Angular 2

杀马特。学长 韩版系。学妹 提交于 2019-12-31 04:01:07
问题 I have created an api in WebAPI as below. public HttpResponseMessage Get() { var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject("Hello World"), Encoding.UTF8, "application/json"); return response; } I am trying to call it from Angular as below Service.ts @Injectable() export class DemoService { constructor(private http:Http){} GetHttpData(){ return this.http.get('http://localhost:54037/api/home') .map((res:Response)=>res

How to stop/break in the middle of chained promises

随声附和 提交于 2019-12-30 11:04:16
问题 I have a chain of $http calls to server. If one call fails I want to display notification to user and stop the chain. At first I thought I can use the $q.reject to stop the chain, but it turned out the program flow continues to the next then 's error handler. I have also tried returning nothing, but the flow still continues. Can I stop the flow mid chain? So for example the script below should print result: |A|D|F instead of result: |A|D|F|E|H|J . If the flow cannot be stopped mid chain, must

How to stop/break in the middle of chained promises

筅森魡賤 提交于 2019-12-30 11:03:57
问题 I have a chain of $http calls to server. If one call fails I want to display notification to user and stop the chain. At first I thought I can use the $q.reject to stop the chain, but it turned out the program flow continues to the next then 's error handler. I have also tried returning nothing, but the flow still continues. Can I stop the flow mid chain? So for example the script below should print result: |A|D|F instead of result: |A|D|F|E|H|J . If the flow cannot be stopped mid chain, must

How to handle error in angular-ui-router's resolve

人盡茶涼 提交于 2019-12-29 03:24:14
问题 I am using angular-ui-router's resolve to get data from server before moving to a state. Sometimes the request to the server fails and I need to inform the user about the failure. If I call the server from the controller, I can put then and call my notification service in it in case the call fails. I put the call to the server in resolve because I want descendant states to wait for the result from the server before they start. Where can I catch the error in case the call to the server fails?

AngularJS $http call in a Service, return resolved data, not promises

北慕城南 提交于 2019-12-28 06:00:12
问题 I want to know if it is possible to make a service call that uses $http so it returns data directly without returning a promise? I have tried to use the $q and defer without any luck. Here is what I mean: I have a service: angular.module('myModule').factor('myService', ['$http', '$q', function($http, $q) { // Public API return { myServiceCall: function() { return $http.get('/server/call'); } }; } ]); And this is how I would call it: // My controller: myService.myServiceCall().then(function

Need to call angular http service from inside loop and wait for the value of the service to return before executing code below call

守給你的承諾、 提交于 2019-12-25 17:23:29
问题 Have a scenario where we have a loop and inside the loop we need to call a http service to get information about each item in the loop. Then based on the result of the service call we need to evaluate and do other work then continue on with each element in the loop. I understand this will not work as coded due to the sync nature of the service call and that the service call itself is a promise. Just looking at the best angular way to accomplish this. In the past I've used $q.all but I'd have

Wait and don't execute a function until a light is set to green

依然范特西╮ 提交于 2019-12-25 17:19:26
问题 I understand that we could use .then to make sure the order of asynchronous calls: return doTask1() .then(function () { return doTask2() }) But sometimes it will be convenient to have a light and to be able to say: wait and don't execute task2 until a light is set to GREEN ; the light is a variable initially set to RED, and can be set to GREEN by task1 or other functions. Does anyone know if it is possible to accomplish this? Edit 1: I think being able to express this is particularly useful

Cancelling an angular service promise

僤鯓⒐⒋嵵緔 提交于 2019-12-25 09:17:41
问题 I have a controller that performs a http request. This request can take anywhere between 2 seconds to 4 minutes to return some data . I have added a button, that users should click to cancel the request if searches take too long to complete. Controller: $scope.search = function() { myFactory.getResults() .then(function(data) { // some logic }, function(error) { // some logic }); } Service: var myFactory = function($http, $q) { return { getResults: function(data) { var deffered = $q.dafer();