AngularJS's $templateCache can be a pain in the ass. Sometimes we don't want templates to be cached. A quick Internet search to disable caching gives the following workaround:
But as I have learnt with the UI Bootsrap module, this may cause AngularJS modules that use $templateCache to break. A solution is to tweak the above workaround so that new cache entries are removed on route change instead of indiscriminately removing all entries:
Hey one query, will the above change forcefully flush template HTML from browser cache also ?
ReplyDeletethanks, really works for me :)
ReplyDeleteThanks, app(2).js works in ionic app. Nice ! :)
ReplyDeleteWhat if My templateUrl contains function
ReplyDeletedid not work for me, still have to clear the browser cache manually every time i make any simple change.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI think I found an updated option for this:
ReplyDelete// Execute every time a state change begins
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
// If the state we are headed to has cached template views
if (typeof (toState) !== 'undefined' && typeof (toState.views) !== 'undefined') {
// Loop through each view in the cached state
for (var key in toState.views) {
// Delete templeate from cache
console.log("Delete cached template: " + toState.views[key].templateUrl);
$cacheFactory.get('templates').remove(toState.views[key].templateUrl);
}
}
});
P.S. I use $stateChangeStart because I use ui-router. You do not have to change $routeChangeStart if you do not want to.