所以,我有这个应用程序使用此代码在加载一些ajax请求时显示和隐藏所有屏幕内容的加载屏幕。
app.config( function( $stateProvider, $urlRouterProvider, $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
}
}
});
})
.run(function( $state, $rootScope, $ionicLoading, $storage )
{
$rootScope.$on('loading:show', function()
{
$ionicLoading.show({template: 'Loading'});
});
$rootScope.$on('loading:hide', function()
{
$ionicLoading.hide();
});
});
当我想加载我使用的东西时:
$http.post( "http://myexample.com.br/json-data", {param1:"1"} ).then(function(result){});
问题在于,在某些情况下,我希望在后台加载某些内容而不显示加载屏幕。
答案 0 :(得分:0)
使用拦截器设置它的方式,每次$http
调用时都会引发那些加载事件。我建议从$rootScope
中删除事件侦听器,并仅将它们应用于您希望加载屏幕显示的各个控制器范围。
答案 1 :(得分:0)
我将$ionicLoading.hide();
放在$http.post
之后。不是最好的,但解决。
$http.post( "http://myexample.com.br/json-data", {param1:"1"}).then(function(result)
{
});
$ionicLoading.hide();