angular-promise

Using function with ng-repeat causing infinite digest loop

余生长醉 提交于 2019-12-12 01:47:48
问题 I have the following piece of code. https://plnkr.co/edit/Tt7sWW06GG08tdJu72Fg?p=preview. Please expand the window fully to see the whole view. I have categories and sub-categories to display in a navbar as shown in the above plunkr. Each category has services/sub-categories to display. I am using 2 nested ng-repeats and the inner one is using the value from the parent iteration of ng-repeat . I have attached a function getServicesByCategory to the inner ng-repeat that calls

How to fail a successful Angular JS $http.get() promise

老子叫甜甜 提交于 2019-12-11 23:27:49
问题 How do I reject or fail a successful $http.get() promise? When I receive the data, I run a validator against it and if the data doesn't have required properties I want to reject the request. I know I can do after the promise is resolved, but it seems like a good idea to intercept errors as soon as possible. I'm familiar with the benefits of $q, but really want to continue using $http. 回答1: You can reject any promise by returning $q.reject("reason") to the next chained .then . Same with $http

The last chained promise does not run

二次信任 提交于 2019-12-11 18:21:25
问题 I have chained a few methods that I'd like to execute in that specific order. The second method deviseLogin() returns a URL that should be passed on the the next method redirect(url) The first and the second method runs, but I never hear anything from the last redirect(url) . Can you see what I'm doing wrong? getUserToken = (username, password) -> console.log "I'm first" $http( method: "POST" url: "/oauth/token" params: params ).success((data, status, headers, config) -> $scope.$storage.token

How to pass data from one asynchronous to another asynchronous function in AngularJS

。_饼干妹妹 提交于 2019-12-11 15:39:18
问题 How to pass global variable value from one function to another function in angular? I have 2 global variables as: $scope.genewtId = null; $scope.data1 = null; I have 2 angular functions which look as below: $scope.getID = function() { Service1.getId("abc").then(function(response){ $scope.genewtId = response.data[0].Id; console.log($scope.genewtId); }, function(error){ console.log(error.statusText); }); }; $scope.getDetails = function() { Service2.getDetails($scope.genewtId).then(function

calling controller function from within a promise in external JS

。_饼干妹妹 提交于 2019-12-11 12:44:48
问题 Ionic Tabs, root of tabs HTML has "RootTabCtrl", and "Tab1" (with "Tab1_Ctrl") has a form, other tabs are disabled . User submits form on Tab1 Tab1 Controller function kicks off. Controller Function calls an external function (not in controller). External function triggers, which executes a promise In promise "results", returned data is processed If X in returned data is true, trigger "RootTabCtrl" function to enable the other disabled tabs. I can track console messages triggering every step

Fill form after http response in angular2

孤人 提交于 2019-12-11 12:13:51
问题 I'm wondering what is a best way to load a form after getting the response from server. I wrote some code where it is getting data from server and in my component I am subscribing to the response, but My UI is loading before even I get the response. I want to use this component for both adding and editing. Component: @Component({ selector: 'gate', templateUrl: '/public/app/views/gate.html', directives: [GateFormComponent, StrategyComponent], providers : [MyService] }) export class MyComponent

How to reuse HTTP request with retry logic in AngularJS

半世苍凉 提交于 2019-12-11 12:11:30
问题 Is it possible to execute the same HTTP request more than once in AngularJS? i.e. without re-defining the same request twice? var retry = false; var req = $http.get( 'ajax.php?a=StartSession&ref=' + code ); req.success(function(res) { alert(res); }); req.error( function(res) { if(retry == false) //run request again req.get(); ? retry = true; }); 回答1: It's what services and factories were made for: app.factory("dataFactory", ["$http", function($http) { return { call: function(code) { return

AngularJS $q.all update/notify not called why?

断了今生、忘了曾经 提交于 2019-12-11 12:09:42
问题 So I have a simple example of using $q.all to batch $resource calls, what I want to know is why is my update handler never called? I would have thought it would be called after each promise is successfully completed? Only the result handler is called. What am I doing wrong? Here is the code snippet: var promises = []; angular.forEach($scope.mappedData, function(item) { var resource = new Resource(item); promises.push(resource.$save()); }); $q.all(promises).then( function(result) { console.log

AngularJS : get object by id from factory

梦想的初衷 提交于 2019-12-11 11:34:19
问题 I have a factory to get an array with all my clientes from the database. Then i need to filter this array by the person id and show only it's data in a single page. I have a working code already, but it's only inside a controller and I want to use it with a factory and a directive since i'm no longer using ng-controller and this factory already make a call to other pages where I need to show client data. This is what i tried to do with my factory : app.js app.factory('mainFactory', function(

Unable to test a rejected promise after migrating to Angular 1.6.3

冷暖自知 提交于 2019-12-11 06:48:30
问题 I have recently updated my application from Angular 1.5 to 1.6.3 and started getting Jasmine unit test failures (with PhantomJS) around promise based code I have written: Possibly unhandled rejection: undefined thrown Reading around I see that the accepted solution is to chain .then() with .catch() blocks to handle the rejections gracefully. I have done this for one of my source files that I am testing to prove this gets past the error which it does. However, it has now uncovered a further