ionic将ionicLoading与http请求绑定

 
  
var app = angular.module('ionicApp', ['ionic'])

app.config(function($httpProvider) {
  $httpProvider.interceptors.push(function($rootScope) {
    return {
      request: function(config) {
        $rootScope.$broadcast('loading:show')
        return config
      },
      response: function(response) {
        $rootScope.$broadcast('loading:hide')
        return response
      }
    }
  })
})

app.run(function($rootScope, $ionicLoading) {
  $rootScope.$on('loading:show', function() {
    $ionicLoading.show({template: 'loading'})
  });

  $rootScope.$on('loading:hide', function() {
    $ionicLoading.hide()
  });
});
原文地址:http://learn.ionicframework.com/formulas/loading-screen-with-interceptors/

你可能感兴趣的:(ionic)