angular-promise

$q promises - Object is not a function

不羁岁月 提交于 2019-12-07 14:55:56
问题 I wanted to run the promises sample from https://docs.angularjs.org/api/ng/service/$q, here is my Code: angular.module('testControllers').controller('testCtrl', ['$scope', '$q', function($scope, $q) { function asyncGreet(name) { // perform some asynchronous operation, resolve or reject the promise when appropriate. return $q(function(resolve, reject) { setTimeout(function() { if (true) { resolve('Hello, ' + name + '!'); } else { reject('Greeting ' + name + ' is not allowed.'); } }, 1000); });

AngularJS Promise retries

廉价感情. 提交于 2019-12-07 05:32:45
问题 I am having some trouble getting a retry function to work and was hoping for some assistance. I have a $resource that I want to have called until a success condition occurs or the maximum retries has been exceeded. The issue I seem to be running into is that within my retry function I am calling another promise and that is where the condition would be checked. I could get the code to function as intended by removing the added promise and creating a default success condition after a few

How to use angular 2 service which returns http promise

一曲冷凌霜 提交于 2019-12-07 04:25:03
问题 I have a trouble with angular 2 here. I use service that return promise but when i try to retrive the response i got an error. i was read this this stact question this my code. this is HotelService.ts import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; //rxjs promises cause angular http return observable natively. import 'rxjs/add/operator/toPromise'; @Injectable() export class HotelService { private BASEURL : any = 'http://localhost:8080/hotel/'; constructor

q.all not working for multiple promises

倾然丶 夕夏残阳落幕 提交于 2019-12-07 04:04:14
问题 I have the following q.all calling to resolve two promises. I checked all the posts and tried all other ways of implementation q.all and its the same case var xyzdeffered = $q.defer(); service1.getServiceDetail1($routeParams.id).then(function(promise) { xyzdeffered.resolve(promise); }); var abcdeffered = $q.defer(); service2.getServiceDetail2($routeParams.id).then(function(promise) { abcdeffered.resolve(promise); }); $q.all([ xyzdeffered, abcdeffered ]).then(function(data) { $scope.variable =

How to return single promise after for loop (which produces a promise on every iteration) is complete?

杀马特。学长 韩版系。学妹 提交于 2019-12-07 01:48:48
问题 I have a problem with my promise return code, I have a function getTagQuotes which contains a for loop which can make multiple calls an API to return data into an array. How my code for this begins below: // If there are tags, then wait for promise here: if (tags.length > 0) { // Setting promise var to getTagQuotes: var promise = getTagQuotes(tags).then(function() { console.log('promise =',promise); // This array should contain 1-3 tags: console.log('tweetArrayObjsContainer ='

Returning an AngularJS $q promise with TypeScript

自作多情 提交于 2019-12-07 00:47:06
问题 I have a service that wraps $http with my functions returning a deferred object. My interface: export interface MyServiceScope { get: ng.IPromise<{}>; } My class: export class MyService implements MyServiceScope { static $inject = ['$http', '$log']; constructor(private $http: ng.IHttpService, private $log: ng.ILogService, private $q: ng.IQService) { this.$http = $http; this.$log = $log; this.$q = $q; } get(): ng.IPromise<{}> { var self = this; var deferred = this.$q.defer(); this.$http.get(

AngularJS then() behaves differently than success()-error() [duplicate]

本小妞迷上赌 提交于 2019-12-06 21:37:22
问题 This question already has answers here : Why are AngularJS $http success/error methods deprecated? Removed from v1.6? (2 answers) Closed last year . As the success() and error() functions are deprecated in AngularJS, I am updating my codes, replacing them with then() . Now according to my understanding, these two pieces of codes should behave identically: $http .get(/* some params */) .success(function() { // success cases here }) .error(function() { // error cases here }); And $http .get(/*

angular controller is executing before factory complete

跟風遠走 提交于 2019-12-06 15:05:02
I have moved some common code to factory. but the controller is executing before factory get loaded. In this case i am getting the blank response(zero results) can anyone suggest the best solution. here is my angular factory, app.factory('TabsFactory', function($resource){ var activetabs = {}; activetabs.getDepositAccountDetails = function() { return $resource('xxxx/:number', {}, { getDepositAccountDetailsService: { method: 'GET', isArray: false } }); } activetabs.getAccountInfo = function(){ return accountinit.accountInfo; } activetabs.setAccountInfo = function(accountnumber, result) { var

Stopping JavaScript Promises from Propagating

纵然是瞬间 提交于 2019-12-06 14:47:18
Imagine I have a promise chain like the one below. If func2 is called, I would like to avoid func3 or func4 from being called altogether. AsyncFunction() .then(func1, func2) .then(func3, func4) At the moment, If I throw an error in func2, func4 would be called. If I return a value in func2, func3 seems to be called. I am using Angular $q. Use nesting for branching control flow. In your case, it would look like this: AsyncFunction().then(function(res) { return func1(res).then(func3, func4); }, func2); 来源: https://stackoverflow.com/questions/27218787/stopping-javascript-promises-from-propagating

Angular js $http factory patterns

北城余情 提交于 2019-12-06 12:55:53
问题 I've a factory named as 'userService'. .factory('userService', function($http) { var users = []; return { getUsers: function(){ return $http.get("https://www.yoursite.com/users").then(function(response){ users = response; return users; }); }, getUser: function(index){ return users[i]; } } }) In the first page, On button click I want to call getUsers function and it will return the 'users' array. I want to use 'users' array in the second page. How can I do it? P.s: I'm using getters and