search

Home  >  Q&A  >  body text

angular.js - angularjs how to disable template caching

angularjs loads different routing templates, but it always uses the cache and reloading the page has no effect. How can I disable the routing mechanism from using cache?

Someone mentioned before that the solution is:

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

I tried it and got an error, 404 template not found

迷茫迷茫2783 days ago692

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-15 17:12:23

    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...

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-15 17:12:23

    How about using ui-router instead of router

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

    or

    $stateProvider.state('stateName', {
            url: return '/foo/bar/' + $.now();
    })

    reply
    0
  • Cancelreply