2016-02-06 87 views
-1

我有這個函數,它加載一個JSON文件並填充範圍。 如果失敗,它將加載一個ionicPopup,其中包含兩個選項:OK和Retry。 我想重新啓動的重試函數調用函數

這裏的功能是我的代碼

$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 the 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(); 
+0

只提取http調用函數變量 –

+0

你是什麼意思? –

回答

0

我DIT這樣的:如果,如果他點擊重試OK返​​回真,假的用戶點擊

然後alertPopup檢查承諾,並因此採取行動

.error(function (data, status, headers, config) { 
    $ionicLoading.hide(); 
    $scope.errorMessage = "Couldn't load the 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();