Kaker
Kaker

Reputation: 645

AngularJS: How to clear cache after load view in ui-router?

Hello I have small probelm: How do you clear the cache after you load a view in ui-router in AngularJS. Please help me

Upvotes: 1

Views: 1051

Answers (2)

Mau Xanh Cua Linh
Mau Xanh Cua Linh

Reputation: 445

app.controller('mainController', function($scope,$templateCache,$rootScope){
$scope.btnUpdate = function(){
$rootScope.$on('$viewContentLoaded', function() {
$templateCache.removeAll();
});
}
});

Upvotes: 0

Sajeetharan
Sajeetharan

Reputation: 222522

Try this,

app.run(function($rootScope, $templateCache) {
    $rootScope.$on('$routeChangeStart', function(event, next, current) {
        if (typeof(current) !== 'undefined'){
            $templateCache.remove(current.templateUrl);
        }
    });
});

Upvotes: 1

Related Questions