ionicLoading 以及网络超时写法

app.js 中,先注册 rootScope 的广播

.run(function ($ionicPlatform, $ionicLoading, ToastService, $rootScope) {
            $rootScope.$on('loading:show', function () {
                  $ionicLoading.show({
                        template: '努力为您加载中...'
                  })
            })
            $rootScope.$on('loading:hide', function () {
                  $ionicLoading.hide()
            })
            .config(function ($httpProvider) {
                  $httpProvider.defaults.timeout = 5000; //默认超时为5秒 $httpProvider.interceptors.push(function ($rootScope) { 
                  return {
                        request: function (config) {
                              $rootScope.$broadcast('loading:show') return config
                        },
                        response: function (response) {
                              $rootScope.$broadcast('loading:hide') return response
                        },
                        responseError: function (response) {
                              $rootScope.$broadcast('loading:hide') return response
                        },
                        requestError: function (config) {
                              $rootScope.$broadcast('loading:hide') return config
                        }
                  }
            })
      })
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27