angular.js - angularjs 如何禁止模板缓存
迷茫
迷茫 2017-05-15 17:10:23
0
2
663

angularjs加载不同的路由模板,但是它总是使用缓存,重新加载页面都没用。如何才能禁止路由机制使用缓存?

之前有人提到解决办法是:

when('/data', {
    templateUrl: 'partial/customer_ask.html?t=' + Math.floor(Date.now() / 1000),
    controller: 'dataController'
})

我试了一下结果报错,404 template not found

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
曾经蜡笔没有小新

404 should be fine, but will the result of t be the same every time?
templateUrl corresponds to a fixed template page. If you write like this, Angular will probably never find it. If you want to pass parameters in the URL, you need to configure it after when.

when('/data/:t', {
    templateUrl: 'partial/customer_ask.html,
    controller: 'dataController'
})

Use in controller
location.path('/data/'+Math.floor(Date.now() / 1000)) //大概这么写忘记了

or the page has a tag

//controller
$scope.randomTime = Math.floor(Date.now() / 1000);
//html
<a href="#/data/{{randomTime}}">走你</a>

You can refer to this example

https://xdsnet.gitbooks.io/an...

世界只因有你

How about using ui-router instead of router

$stateProvider.state('stateName', {
        cache: false,
        .....
})

or

$stateProvider.state('stateName', {
        url: return '/foo/bar/' + $.now();
})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template