angular-promise

$http issue - Values can't be returned before a promise is resolved in md-autocomplete Angular Material

心不动则不痛 提交于 2019-11-30 15:58:38
I'm using Angular Material md-autocomplete in my project. In that I'm getting the suggest listing from the Service Host via ajax call using $http service. Issue : $http issue - Values can't be returned before a promise is resolved in md-autocomplete Angular Material My Requirement : I need an updated Suggestion List using remote data sources in md-autocomplete Angular Material - Ajax $http service. I used the approach as mentioned in Angular Material link https://material.angularjs.org/latest/demo/autocomplete Source Code: Scenario 1: HTML Source Code: <md-autocomplete flex required md-input

AngularJS : returning data from service to controller

一世执手 提交于 2019-11-30 07:18:23
I am trying to create a service to get json and pass it to me homeCtrl I can get the data but when a pass it to my homeCtrl it always returns undefined. Im stuck. My Service: var myService = angular.module("xo").factory("myService", ['$http', function($http){ return{ getResponders: (function(response){ $http.get('myUrl').then(function(response){ console.log("coming from servicejs", response.data); }); })() }; return myService; } ]); My Home Controller: var homeCtrl = angular.module("xo").controller("homeCtrl", ["$rootScope", "$scope", "$http", "myService", function ($rootScope, $scope, $http,

Chain Angular $http calls properly?

£可爱£侵袭症+ 提交于 2019-11-30 00:50:35
问题 I have been reading about $q and promises for days now and I seem to understand it...somewhat. I have the following situation in practice: An $http request is made and checks whether a subsequent call can be made. If the first call fails, return "no data", if it succeeds and says a call can be made, the second call is made, if not - "no data" again. If the second call succeeds, it returns data, if not - "no data". It looks like this (approximately, I simplified for general idea, so don't

$http issue - Values can't be returned before a promise is resolved in md-autocomplete Angular Material

旧城冷巷雨未停 提交于 2019-11-29 22:02:46
问题 I'm using Angular Material md-autocomplete in my project. In that I'm getting the suggest listing from the Service Host via ajax call using $http service. Issue : $http issue - Values can't be returned before a promise is resolved in md-autocomplete Angular Material My Requirement : I need an updated Suggestion List using remote data sources in md-autocomplete Angular Material - Ajax $http service. I used the approach as mentioned in Angular Material link https://material.angularjs.org/latest

scope variable undefined outside `.then` method

∥☆過路亽.° 提交于 2019-11-29 17:58:21
I changed the scope variable in an if statement and outside the if statement it turned into an undefined variable app.controller("Login", function($scope, $window,$http){ var status; $scope.loginUser = function(logData){ $http.post('/corporate/login',logData).then(function(response){ var data = response.data var status = data.success; if(status == true){ $scope.logStatus = true; console.log($scope.logStatus); // prints true }else{ $scope.logStatus = false; } }) console.log($scope.logStatus); //prints undefined } }); outside ... it turned into an undefined variable It did not "turn into" an

ControllerProvider in UI-router results in error

允我心安 提交于 2019-11-29 16:40:18
I have a ui-router StateProvider and need to pick between controllers & views based on external data, so I used TemplateProvider and ControllerProvider . If I only had the TemplateProvider it all works fine, but when I add the ControllerProvider I get this error: Error: [ng:areq] Argument 'fn' is not a function, got Object http://errors.angularjs.org/1.3.1/ng/areq?p0=fn&p1=not%20aNaNunction%2C%20got%Object at REGEX_STRING_REGEXP (http://localhost:48510/Scripts/Vendor/Angular/1-angular.js:80:12) at assertArg (http://localhost:48510/Scripts/Vendor/Angular/1-angular.js:1577:11) at assertArgFn

Do I really need to return a promise in test when using Chai as Promised?

时光毁灭记忆、已成空白 提交于 2019-11-29 12:09:43
Chai as Promised documentation states as follows: Notice : either return or notify(done) must be used with promise assertions. And the examples on the site are as follows: return doSomethingAsync().should.eventually.equal("foo"); doSomethingAsync().should.eventually.equal("foo").notify(done); The thing is; I actually wrote a test using chai as promised without returning the promise. Like so: it('should resolve user', function () { $state.get(state).resolve.user(dataservice, { userId: testUser.id }).should.eventually.eq(testUser); $rootScope.$apply(); }); And it works perfectly fine. I am sure

Is there a shortcut to proxy-resolve/reject a promise to an Angular $q deferred?

混江龙づ霸主 提交于 2019-11-29 11:52:29
Given an unresolved deferred ( dfd ), and a then-able promise ( promise ), which may or may not be deferred, is there a way to 'proxy' the promise into the deferred? The semantics should be as so: promise.then(dfd.resolve, dfd.reject); The $q documentation only mentions handling of rejected promises (and furthermore, only promises rejected in a certain way): defered.resolve(value) – resolves the derived promise with the value. If the value is a rejection constructed via $q.reject, the promise will be rejected instead. This makes it unclear if dfd.resolve(promise) is valid/supported. Also, I

Possibly unhandled rejection in Angular 1.6

半世苍凉 提交于 2019-11-29 02:52:33
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 x = null; var y = x.y; //do something with the result }); I'm getting clear error message: TypeError: Cannot read property 'y' of null But in version 1.6 with the same code I'm getting a different error: Possibly unhandled rejection: {} undefined I know that this is related to this change , and the single solution is quite simple by adding .catch() block: service

Stop request in angularjs interceptor

三世轮回 提交于 2019-11-28 23:17:39
How can I stop a request in Angularjs interceptor. Is there any way to do that? I tried using promises and sending reject instead of resolve ! .factory('connectionInterceptor', ['$q', '$timeout', function($q, $timeout) { var connectionInterceptor = { request: function(config) { var q = $q.defer(); $timeout(function() { q.reject(); }, 2000) return q.promise; // return config; } } return connectionInterceptor; } ]) .config(function($httpProvider) { $httpProvider.interceptors.push('connectionInterceptor'); }); The $http service has an options timeout to do the job. you can do like: angular.module