简体   繁体   中英

issue about abort http request on angular.js

I try to write an interceptor that controls whether internet connection exists or not. If connection does not exist, it will show a message that "You have not connection" and it aborts the http request,else it will make htt prequest.How can I make this? Thanks in advance

you should use the following plugin: cordova plugin add cordova-plugin-network-information

code example:

module.controller('MyCtrl', function($rootScope, $cordovaNetwork) {

  document.addEventListener("deviceready", function () {

    var type = $cordovaNetwork.getNetwork()

    var isOnline = $cordovaNetwork.isOnline()

    var isOffline = $cordovaNetwork.isOffline()


    // listen for Online event
    $rootScope.$on('$cordovaNetwork:online', function(event, networkState){
      var onlineState = networkState;
    })

    // listen for Offline event
    $rootScope.$on('$cordovaNetwork:offline', function(event, networkState){
      var offlineState = networkState;
    })

  }, false);
});

http://ngcordova.com/docs/plugins/network/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM