In my ionic application I have disabled the prefetching of templates for different route views.
For showing a global loading screen for http requests I followed the formula. But since there are htp request for templates screens also there is a loading screen whenever I switch my views. Can anyone suggest a standard way to bypass it.
In your $http Interceptor you get the request config object -> maybe you can add a custom key to that config, if you call $http -> and there you can decide if it is a template request or not.
like:
$http({method: 'get', url: 'TEMPLATEURL', isTemplate: true}).success(....)
in you interceptor
$httpProvider.interceptors.push(function($rootScope) {
return {
request: function(config) {
if (!config.isTemplate) {
$rootScope.$broadcast('loading:show')
}
return config
},
response: function(response) {
$rootScope.$broadcast('loading:hide')
return response
}
}
})
Maybe it is working
thanks @bengtler … I don’t think I can add a custom attribute in http template requests made while switching views. But your idea of config worked. Did this instead:
var isTemplateURL = function(config) {
var url = config.url;
//console.log(url);
if(url) {
var extension = ".tpl.html";
return url.indexOf(extension,url.length-extension.length) !== -1;
} else {
return false;
}
};
$httpProvider.interceptors.push(function($rootScope) {
return {
request: function(config) {
if (!config.isTemplate) {
$rootScope.$broadcast('loading:show')
}
return config
},
response: function(response) {
$rootScope.$broadcast('loading:hide')
return response
}
}
We follow an convention of adding .tpl.html to template files to distinguish them from regular HTML files.
Could you please check if custom attribute would work?
You can add attributes in request you form (by using $http or angular resources) but while switching views these request requests are done by angular to fetch the view from templates. I don’t know any way to hack into that.