Search Posts

Category: angular-promise

Setting a timeout for each promise within a promise.all

I am able to successfully perform a Promise.all, and gracefully handle resolves and rejects. However, some promises complete within a few milliseconds, some can/could take a while. I want to be able to set a timeout for each promise within the Promise.all, so it can attempt to take a maximum of say 5seconds. getData() { var that = this; var tableUrls = [‘’,’’]; var spoonUrls = [‘’,’’]; var tablePromises = that.createPromise(tableUrls); var spoonPromises = that.createPromise(spoonUrls); […]

Service returning before all http calls have completed

I have a controller calling a service, which performs a number of http calls and returns back a set of data to my controller. The problem i am facing is that my service returns some data (typically emtpy) before all the http calls have been completed, and as a result, $scope.myForksLinks is undefined. Controller: myService.getMyData() .then(function(response) { $scope.myUrl = response.myForksLinks; }); MyService: handleResolveReject() { return promise.then(function(v) { return {v:v, status: “resolved”}; }, function(e) { return […]

angularjs $http(config) ith data from form not working

I have an issue with $http in angularjs : app.controller(‘ctrlProfil’, function($scope, $http){ $scope.loginProfil = “<?= $_SESSION[‘login’]?>”; $scope.mdpProfil = “<?= $_SESSION[‘mdp’]?>”; $scope.emailProfil = “<?= $_SESSION[’email’]?>”; var config = { method: ‘POST’, url: ‘modifProfil.php’, data: $(‘#formProfil’).serialize() } $scope.submit = function(){ $http(config). then(function(response){ console.log(response); console.log($(‘#formProfil’).serialize()); }) } }); my form => <form id=”formProfil” ng-submit=”submit()”> <p><span>Bonjour </span><input type=”text” name=”loginProfil” value=”{{loginProfil}}”/></p> <p>Mon mot de passe: <input type=”text” name=”mdpProfil” value=”{{mdpProfil}}”/></p> <p> Email: <input type=”email” name=”emailProfil” value=”{{emailProfil}}”/></p> <input class=”btn btn-primary” type=”submit” value=”Enregistrer”/> […]

ui-route: when the page reloaded after log in, it throws me 404 error . Can any one help me out?without reloading it works fine

I’m new to ui-routing. Actually, i’m trying to load the dashboard after login successfully.I’m able to achieve that, but when I reload the page after log in ,it’s throwing me 404 error not found. when I don’t reload the page it’s working fine. Take a look at my plunker and please help me out Source: AngularJS

ng-show directive not working Angular (controllerAs issue)

I am building a single-page app with a timer and 2 buttons: 1st one shows up on initial state (onBreak=false), and handles a 25min-timer 2nd one shows up when the 1st timer is over (onBreak=true), and handles a 5min-timer Here is the HTML : <h1>{{ home.time | formattime }}</h1> <button type=”button” class=”btn btn-primary” ng-hide=”onBreak” ng-click=”home.workTimer()” ng-bind=”home.startOrResetWork”> </button> <button type=”button” class=”btn btn-primary” ng-show=”onBreak” ng-click=”home.breakTimer()” ng-bind=”home.startOrResetBreak”> </button> The controller : (function() { function HomeCtrl($interval) { var $ctrl […]

How to logout when my token is expired and unauthorized?

The below code is my service.js.How to log out when my token is expired and unauthorized? Do we need to set local storage? can someone help me or suggest me how can I achieve the result which I’m looking for.Thanks in Advance ‘use strict’; angular.module(‘Authentication’) .factory(‘AuthenticationService’, [‘Base64’, ‘$http’, ‘$cookieStore’, ‘$rootScope’, ‘$timeout’, function (Base64, $http, $cookieStore, $rootScope, $timeout) { var service = {}; service.Login = function (callback) { //authenticate data http $‘’) .then(function (response) { callback(response); […]

Data from database is not loaded to a variable on page load using angular

On page load, I get data from a database and place it in $scope.x. In my network tab, I get the list from my database but it is not loaded to the variable which I will soon be needing in a dropdown list by using ng-repeat. After the page load, however, when I click a button that retrieves data and place it in the $scope.x, I get the values already. If I do it like, […]

AngularJS – stateful service object using a promise updating multiple components in realtime

I asked a similar question here, but I realize that I may not have been specific enough, even though I learned a lot from the feedback. I am having trouble understanding if my approach to multi-component communication via services is going in the right direction or not, particularly when the service uses a promise to load its data AND when the service needs to keep track of its changing state. Finally, I want to understand […]

Return an array from a function with a promise

I need to return the array lotSpecItems from this function once it is populated: public getLotSpecItems(id: number) { let toReturn = this.resourceClass.getLotSpecItems({ lotId: id }); let lotSpecItems = []; return toReturn.$promise.then(lotSpecItemsArray => { lotSpecItemsArray.forEach(lotSpecItem => { lotSpecItems.push(this.$di.logicFactory.getLotSpecLogic().mapLotSpecItem(lotSpecItem)); }); }); } The $promise is an angular js promise: (property) angular.resource.IResourceArray<any>.$promise: ng.IPromise<ng.resource.IResourceArray<any>> Client code (can be edited to not expect a promise): $onInit() { this.lotLogic.getLotSpecItems( => { this.searchResults = results; console.log(this.searchResults); }); It currently returns undefined. What […]

$q in Angular or Promises in ES6

I have a project using ES6 and AngularJS, and as far as I found, AngularJS $q promises is synchronous but ES6 promises not. Right? The question is, what are the differences? and when should I use $q or ES6? I know what is the difference between Synchronous and Asynchronous, but got confused between new Promise and AngularJS $q. raise from here Source: AngularJS

Next Page »