Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I am facing web browser cache problem when I am using anguler js with MVC.
No changes reflect because page is already cached so its very irritating to open a private window to see the changes.

Please help.

What I have tried:

JavaScript
myModule.config(['$httpProvider', function ($httpProvider) {
    $httpProvider.interceptors.push('noCacheInterceptor');
}]).factory('noCacheInterceptor', function () {
    return {
        request: function (config) {
            console.log(config.method);
            console.log(config.url);
            if (config.method == 'GET') {
                var separator = config.url.indexOf('?') === -1 ? '?' : '&';
                config.url = config.url + separator + 'noCache=' + new Date().getTime();
            }
            console.log(config.method);
            console.log(config.url);
            return config;
        }
    };
});
Posted
Updated 20-Apr-17 3:19am
v2

1 solution

it will clear the cache on every ng-view content change

JavaScript
myApp.run(function ($rootScope, $templateCache) {
    $rootScope.$on('$viewContentLoaded', function () {
        $templateCache.removeAll();
    });
});
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900