angular-promise

Angular $q returning promise multiple $http calls

☆樱花仙子☆ 提交于 2019-12-19 03:13:12
问题 I'm working on an $http call that loops over each of multiple api's and returns all of the data in one object. I usually have the promise ready to resolve when the $http call has been made. Similar to this: function getAllData(api) { return $http({ method: 'GET', url: '/api/' + api }) .then(sendResponseData) .catch (sendGetVolunteerError); } The current function I have loops over each api and pushes each object in the api into an array and then pushes it into an overall array. I had this

scope variable undefined outside `.then` method

末鹿安然 提交于 2019-12-18 09:49:18
问题 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);

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

冷暖自知 提交于 2019-12-18 07:06:56
问题 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

$q promise with Underscore _each

╄→гoц情女王★ 提交于 2019-12-17 16:58:41
问题 So I have a method in a angularjs server that is calling a method that returns a promise for each method in a array. I am using underscore _each to loop through the array. I want to wait until the entire array is processed before I call the final line of code in the method.. So... function ProcessCoolStuff(coolStuffs) { var stuff = []; _.each(coolStuffs, function(coolStuff) { //Some method using $q to return makeStuffCooler(coolStuff).then(function(coolerStuff) { stuff.push(coolerStuff); });

How to create a AngularJS promise from a callback-based API

╄→гoц情女王★ 提交于 2019-12-17 10:04:13
问题 wifiservice.js: angular.module('app.WifiServices', []) .factory('WifiService', function(){ var unique_array = angular.fromJson('[]'); function win_wifi(e){ alert("Success"); } function fail_wifi(e){ alert("Error"); } function connectWifi(wifi_ssid){ WifiWizard.connectNetwork(wifi_ssid, win_wifi, fail_wifi); } function listHandler(a){ var network_array = []; for(var i=0; i<a.length; i++){ network_array.push("SSID: " + a[i].SSID + " Signal: " + a[i].level); } unique_array = network_array.filter

Angular 1.6.0: “Possibly unhandled rejection” error [duplicate]

北城以北 提交于 2019-12-17 08:55:12
问题 This question already has answers here : Possibly unhandled rejection in Angular 1.6 (9 answers) Closed last year . We have a pattern for resolving promises in our Angular app that has served us well up until Angular 1.6.0: resource.get().$promise .then(function (response) { // do something with the response }, function (error) { // pass the error the the error service return errorService.handleError(error); }); And here is how we are triggering the error in Karma: resourceMock.get = function

Angular 1.6.0: “Possibly unhandled rejection” error [duplicate]

拜拜、爱过 提交于 2019-12-17 08:55:10
问题 This question already has answers here : Possibly unhandled rejection in Angular 1.6 (9 answers) Closed last year . We have a pattern for resolving promises in our Angular app that has served us well up until Angular 1.6.0: resource.get().$promise .then(function (response) { // do something with the response }, function (error) { // pass the error the the error service return errorService.handleError(error); }); And here is how we are triggering the error in Karma: resourceMock.get = function

How do I use Bluebird with Angular?

主宰稳场 提交于 2019-12-17 04:19:05
问题 I tried using Angular with Bluebird promises: HTML: <body ng-app="HelloApp"> <div ng-controller="HomeController">{{name}} {{also}}</div> </body> JS: // javascript var app = angular.module('HelloApp', []); app.controller("HomeController", function ($scope) { var p = Promise.delay(1000).then(function () { $scope.name = "Bluebird!"; console.log("Here!", $scope.name); }).then(function () { $scope.also = "Promises"; }); $scope.name = "$q"; $scope.also = "promises"; }); window.app = app; [Fiddle]

How do I use Bluebird with Angular?

对着背影说爱祢 提交于 2019-12-17 04:17:41
问题 I tried using Angular with Bluebird promises: HTML: <body ng-app="HelloApp"> <div ng-controller="HomeController">{{name}} {{also}}</div> </body> JS: // javascript var app = angular.module('HelloApp', []); app.controller("HomeController", function ($scope) { var p = Promise.delay(1000).then(function () { $scope.name = "Bluebird!"; console.log("Here!", $scope.name); }).then(function () { $scope.also = "Promises"; }); $scope.name = "$q"; $scope.also = "promises"; }); window.app = app; [Fiddle]

How to access the value of a promise?

痞子三分冷 提交于 2019-12-16 23:55:33
问题 I'm looking at this example from Angular's docs for $q but I think this probably applies to promises in general. The example below is copied verbatim from their docs with their comment included: promiseB = promiseA.then(function(result) { return result + 1; }); // promiseB will be resolved immediately after promiseA is resolved and its value // will be the result of promiseA incremented by 1 I'm not clear how this works. If I can call .then() on the result of the first .then() , chaining them