Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49229

Manage connection rest api

$
0
0

@mcnamara wrote:

how can I handle a call to rest bees when they are not connected to the internet? I tried with this codice..ma does nothing

controller('AppCtrl',function($scope, $http,$sce,$timeout,$ionicLoading){

     document.addEventListener("online", function() {
       // Setup the loader
  $ionicLoading.show({
    content: 'Loading',
    animation: 'fade-in',
    showBackdrop: true,
    maxWidth: 200,
    showDelay: 0
  })

  //carico il link per la chiamata al REST
  var wordpressUrl ="http://www.mysites.it/sites/wordpress/wp-json/wp/v2/posts";
  $scope.$on('$ionicView.enter', function(){
    console.log('View1 Entered');
     $scope.doRefresh();
  });

  $scope.loadPost = function() {
  // effetuo la chimamata REST API
  $http.get(wordpressUrl)

    // risposta positiva
    .success(function(response,$timeout){
      console.log("Reveived getPosts via HTTP: ", response, status);
    // Loading Json
    $ionicLoading.hide();
    $scope.posts = response;
    console.log( response );
    })// fine success

    //risposta negativa
    .error(function(response, status){
      console.log("Error while received response. " + status + response);
    });// fine error

   }// End LoadPost


  // Refresh all'apertura della pagina
  $scope.doRefresh = function() {

    console.log('Refreshing!');
    $timeout( function() {
      //simulate async response
      $scope.loadPost();
      //Stop the ion-refresher from spinning
      $scope.$broadcast('scroll.refreshComplete');
    }, 1000);

  };// Fine Refresh
      }, false);// end event online
})// Fine Controller

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 49229

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>