angular-promise

Call a promise function multiple times until condition met from another promise function

╄→гoц情女王★ 提交于 2019-12-09 03:09:28
I have the following code: http://jsfiddle.net/kyy4ey10/4/ $scope.count = 0; function getActiveTasks() { var deferred = $q.defer(); setTimeout(function() { $scope.count++; deferred.resolve(); },1000) return deferred.promise; } // i want to put this inside the function, but it doesn't work var deferred = $q.defer(); function callPromise() { getActiveTasks().then(function(){ if($scope.count < 5){ callPromise(); } else{ deferred.resolve() } }) return deferred.promise; } callPromise().then(function(){ $scope.count = "done" }); If I put: var deferred = $q.defer(); inside the callPromise() function,

can't simply use ES6 promise to update data in ng-repeat?

六眼飞鱼酱① 提交于 2019-12-08 10:36:10
问题 I'm trying to build a drill-down list with angular and es6 promise. Without using promise my code works as demoed in the snippet below. Every time you click the parent, it expands the children (just foo and bar in the sample for simplicity). angular.module('demo', []) .controller('DemoController', ['$scope', 'dataService', function($scope, dataSvc) { $scope.entities = dataSvc.loadInitialData(); }]) .directive('drillDown', ['$compile', 'dataService', function($compile, dataSvc) { return {

Call a promise function multiple times until condition met from another promise function

本小妞迷上赌 提交于 2019-12-08 06:16:59
问题 I have the following code: http://jsfiddle.net/kyy4ey10/4/ $scope.count = 0; function getActiveTasks() { var deferred = $q.defer(); setTimeout(function() { $scope.count++; deferred.resolve(); },1000) return deferred.promise; } // i want to put this inside the function, but it doesn't work var deferred = $q.defer(); function callPromise() { getActiveTasks().then(function(){ if($scope.count < 5){ callPromise(); } else{ deferred.resolve() } }) return deferred.promise; } callPromise().then

angular controller is executing before factory complete

ⅰ亾dé卋堺 提交于 2019-12-08 05:50:35
问题 I have moved some common code to factory. but the controller is executing before factory get loaded. In this case i am getting the blank response(zero results) can anyone suggest the best solution. here is my angular factory, app.factory('TabsFactory', function($resource){ var activetabs = {}; activetabs.getDepositAccountDetails = function() { return $resource('xxxx/:number', {}, { getDepositAccountDetailsService: { method: 'GET', isArray: false } }); } activetabs.getAccountInfo = function(){

Angularjs custom directive using http promise not binding with template

六眼飞鱼酱① 提交于 2019-12-08 03:33:29
I am new to angularjs and want to add new feature in existing code. But code is not working as expected. I know i am not doing it the right way. Please correct me where is the mistake. I don't know why controller is not used but directive is used in this approach? Here is my custom service and custom directive directive code. Service code: angular.module("quickquiz-builder").service("SettingsService", function ($http, $q) { return { /* Return deffered promise response */ get: function() { var deferred = $q.defer(); $http.get('get.php') .then(function(response){ var config = response.data

What is about digest cycle in angular?

陌路散爱 提交于 2019-12-08 03:33:14
问题 Let we have the code in the control's method executed when, for example, we push a button $timeout(function() { $scope.names = ['A', 'B', 'C']; }, 0, false).then(function() { $scope.names.push('D'); }) in this case we will not see any changes at the screen because the digest cycle will not be running But if we wrote this $timeout(function() { $scope.names = ['A', 'B', 'C']; }, 0, false).then(function() { $scope.names.push('D'); return $q.when(); }) we will see changes because when we return

Stopping JavaScript Promises from Propagating

我只是一个虾纸丫 提交于 2019-12-08 03:13:36
问题 Imagine I have a promise chain like the one below. If func2 is called, I would like to avoid func3 or func4 from being called altogether. AsyncFunction() .then(func1, func2) .then(func3, func4) At the moment, If I throw an error in func2, func4 would be called. If I return a value in func2, func3 seems to be called. I am using Angular $q. 回答1: Use nesting for branching control flow. In your case, it would look like this: AsyncFunction().then(function(res) { return func1(res).then(func3, func4

Angularjs - $http success vs then

佐手、 提交于 2019-12-08 02:34:14
问题 I want to ask about the difference about this method My concern is difference between .then and .success, function and also .error thanks. // Simple GET request example: $http({ method: 'GET', url: '/someUrl' }).then(function successCallback(response) { // this callback will be called asynchronously // when the response is available }, function errorCallback(response) { // called asynchronously if an error occurs // or server returns response with an error status. }); and // Simple GET

AngularJS: How to get $http result as returned value of a function?

隐身守侯 提交于 2019-12-07 20:02:13
问题 Inside my controller I need a function that takes a parameter and returned a URL from server. Something like this: $scope.getPoster = function(title) { return $http.get("http://www.omdbapi.com/?t=" + title + "&y=&plot=short&r=json"); }; And inside my view I need to pass the title this way and get result as src for ng-src : <div class="col-sm-6 col-md-3" ng-repeat="movie in movies"> <div class="thumbnail"> <img class="poster" ng-src="{{getPoster(movie.Title)}}" alt="{{movie.Title}}"> <div

angularjs chain http post sequentially

*爱你&永不变心* 提交于 2019-12-07 16:32:41
问题 In my application, I am storing data in local storage and trigger async http post in the background. Once successfully posted, the posted data gets removed from local storage. When http post is in process, there may be more data added to local storage so I need to queue up the post and sequentially process it because, I need to wait for the local storage to be cleared from the successful posts. The task should be called recursively until there is data in local storage. taskQueue: function ()