angular-promise

Component : ui-router resolve will not inject into controller, data undefined

╄→гoц情女王★ 提交于 2019-12-23 01:41:36
问题 I have this problem using resolve with component & ui-router, the data "after" resolving promise are "undefined" in a controller Service: class userService { constructor ($http, ConfigService, authService) { this.$http = $http; this.API_URL = `${ConfigService.apiBase}`; this.authService = authService; } testAuth () { return this.$http.get(this.API_URL + '/test-auth') } getCollaboratores () { return this.$http.get(this.API_URL + '/collaboratores').then( (resolve) => { // promise resolve

AngularJS : How to use the $q promise feature in this situation to wait for data to be ready?

允我心安 提交于 2019-12-22 10:05:13
问题 I have a Controller which starts an API call in a Factory . Currently I start the call, then I have a function after that call to check the status of the Array . However I'm not sure how to force it to wait here while the data is being gathered, thus the need for some kind of $q implementation. As you can see in the screenshot below, vs.tickers returns an empty Object, or Array. Then finally the console.log in GetTickersFactory fires: 1st Controller if (root.tickerType === 'portfolio') { //

Angular promises run conditionally

南楼画角 提交于 2019-12-22 08:25:13
问题 I'd like to perform an asynch function conditionally, but I think I'm missing the correct syntax to say what I want. this.doUpToThreeThings = function(skipTheMiddleStep) { return doFirstThing().then(function (result) { if (skipTheMiddleStep) { return doThirdThing(); } else { return doSecondThing(); } }).then(function (result) { if (skipTheMiddleStep) { return "ok"; // return what? } else { return doThirdThing(); } }); } By the time we get to the second then, I don't know if the first block

Angular/Jasmine testing with deffered promises

时光总嘲笑我的痴心妄想 提交于 2019-12-22 08:03:53
问题 I am testing a controller using a combination of angular and jasmine, and am not completely sure about using deffered promises. This is my spec code. describe('Controller Tests', function(){ var scope, searchAPI; beforeEach(function(){ var mockSearchAPI = {}; module('myApp', function($provide){ $provide.value('searchAPI', mockSearchAPI); }); }); inject(function($q){ var testData = {"message":"hi"}; mockSearchAPI.executeSearch = function(){ var defer = $q.defer(); defer.resolve(testData);

Swallowed message : Error: Uncaught (in promise): [object Undefined]

南笙酒味 提交于 2019-12-22 04:02:22
问题 My login component briefly displays before being removed by an error message about an undefined object in a promise. Here is the promise definition: static init(): Promise<any> { KeycloakClientService.auth.loggedIn = false; return new Promise((resolve, reject) => { const keycloakConfig = { url: environment.KEYCLOAK_URL, realm: environment.KEYCLOAK_REALM, clientId: environment.KEYCLOAK_CLIENTID, 'ssl-required': 'external', 'public-client': true }; const keycloakAuth: any = new Keycloak

Executing then after catch

余生颓废 提交于 2019-12-21 08:05:30
问题 I have the following fiddle: http://jsfiddle.net/thelgevold/3uv9nnjm/6/ angular.module('hello',[]).controller('helloController',function($q){ console.clear(); function someService(){ var deferred = $q.defer(); deferred.reject({e:'error'}); return deferred.promise; } function callService(){ return someService().then(function(obj){ console.log('first then'); }). catch(function(e){ console.log('error1'); var deferred = $q.defer(); deferred.reject({e:'error'}); return deferred.promise; }); }

Typescript async/await and angular $q service

别来无恙 提交于 2019-12-20 11:43:08
问题 New TypeScript async/await feature uses ES6 promises. AngularJS uses $q service promises with slightly different interface. Is there any way to use TypeScript async/await feature with $q service promises? 回答1: You can make it work like this: angular.module('your app') .run(['$window', '$q', function($window, $q) { $window.Promise = $q; }]); 回答2: I do not think you will be able to use them directly. But it should be quite easy to convert q promise into a++ promise, something like this:

Angular $q .catch() method fails in IE8

ε祈祈猫儿з 提交于 2019-12-20 08:48:36
问题 I'm experiencing a weird bug on IE8 while trying to catch a promise reject (promise returned by a basic ngResource call) : This code work with .then(success, fail) syntax : promise.then(function(response) { // success }, function(response) { // error }); but this one fails with .then(success).catch(fail) syntax : promise.then(function(response) { // success }) .catch(function(response) { // error }); and the IE error pointing to the .catch() line is : Expected identifier Am I doing something

Chaining Angular promise rejections

半腔热情 提交于 2019-12-20 07:18:34
问题 I have a chained promise and in the case of a rejection for either of the promises, I need to perform an async operation (get the translated error message). As I've already got a chained promise on success, I assume it's not possible to also chain on rejection - I am attempting to simply nest the async calls, but I'm not getting the resolved promise back from deferred.reject(deferredRejection.promise); below. Pointers appreciated! login: function(email, password) { var deferred = $q.defer();

How to use an Ng-if with Firebase

痞子三分冷 提交于 2019-12-20 05:40:11
问题 I know that the ng-if directive creates a new child scope and I would like to know HOW and IF it is possible to play a ng-if into an other one. For now I can't see any icons. I've tried ng-hide, but I saw the two icons in the same time, impossible to fix that problem...I also tried ng-show, but with the same results as ng-if. Set() function returns true or false, it's working because I can see the result in the console. Any ideas ? $scope.set = function($r) { firebase.database().ref('events/'