angularjs - Recall function from function -
i have function, loads json file , populates scope. if fails, loads ionicpopup 2 choices, ok , retry. i'd relaunch function on retry
here's code
$scope.loadevents = function () { $http.get('https://api.paris.fr/api/data/1.4/quefaire/get_activities/?token=[foobar]&cid=3,9,18,20,16,10,4,37,1,29,30,11,42,25,5,33,8,39,6,40,17,38,34,32,2,44,23&tag=6,4,7,44,2,45,48&created=0&start=0&end=0&offset=1&limit=50',{header : {'content-type' : 'application/json; charset=utf-8'}}) .success(function (data) { $ionicloading.hide(); $scope.products = data.data; var randomproduct = math.round(math.random() * ($scope.products.length - 1)) $scope.currentproduct = angular.copy($scope.products[randomproduct]); $scope.currentproduct.image = $scope.checkhttp(); }) .error(function (data, status, headers, config) { $ionicloading.hide(); $scope.errormessage = "couldn't load list of events, error # " + status; var alertpopup = $ionicpopup.confirm({ title: 'could not load list of events, error #0', template: '', buttons: [ {text: 'ok'}, { text: '<b>retry</b>', type: 'button-positive', ontap: function(e) { console.log("reessayer"); //retry loadevents() return false; }}] }); console.log($scope.errormessage); }); } $scope.loadevents();
i dit this: if user clicks on ok returns true, , false if clicks on retry
then alertpopup checks promise , acts consequently
.error(function (data, status, headers, config) { $ionicloading.hide(); $scope.errormessage = "couldn't load list of events, error # " + status; var alertpopup = $ionicpopup.confirm({ title: $scope.errormessage, template: '', buttons: [ {text: 'ok', ontap: function(e) { return true; } }, { text: '<b>retry</b>', type: 'button-positive', ontap: function(e) { console.log("reessayer"); return false; }}] }); alertpopup.then(function(res) { if(!res) $scope.loadevents(); else { console.log("stop"); } }); console.log($scope.errormessage); }); } $scope.loadevents();
Comments
Post a Comment