Angularjs - 如何清除templateUrl的$ routeProvider的缓存 [英] Angularjs - how to clear $routeProvider's caches of templateUrl

查看:265
本文介绍了Angularjs - 如何清除templateUrl的$ routeProvider的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序,我使用的前端和Grails的后端AngularJS(1.0.8),真正的基本用例。在应用程序中的布局我有一个语言切换器允许用户更改语言。切换的语言,但它确实新的HTTP请求来检索该网页。 Grails的所有渲染语言相关的东西(即标签)正确地翻译。这仅适用于浏览器,FF,因此而不是IE浏览器。 IE呈现正确的语言只是它是由主请求呈现布局。

I have really basic use case in my app where I use AngularJS (1.0.8) for front end and Grails for back end. In the app layout I have a language switcher which allows the user to change the language. Switching the language, it does new http request to retrieve the page. Grails renders all language related stuff (i.e. labels) properly translated. This only works for Chrome, FF, and so but not for IE. IE renders proper language just for layout which is rendered by the main request.

我所在的问题。我已经定义 $ routeProvider 其中,我加载应用内容的专业。它默认缓存,因此IE不加载 templateUrl 因为它加载它们的缓存 $ routeProvider

I located the problem. I have defined $routeProvider where I load major of the app content. It is cached by default, therefore IE doesn't load templateUrl of $routeProvider because it loads them from cache:

myApp.config(function ($routeProvider) {
        $routeProvider.
            when('/', {controller: 'MyCtrl', templateUrl: '/eshop/myConfig'})
});

我不明白就是为什么它能适用于所有其他浏览器。

What I don't get is why it works in all other browsers.

我发现了一些后如何清除缓存,但他们不会为我工作。有我的解决方案吗?如果没有,我觉得 $ routeProvider 我的用例完全无用。
后我发现:

I found some post how to clear cache but they doesn't work for me. Is there any solution for me? If not, I find $routeProvider completely useless for my use case. Post I found:

  • angularjs clear history when view loaded
  • AngularJS disable partial caching on dev machine

推荐答案

下面应该这样做。您可以通过使用$ templateCache,所以$ routeProvider将每次访问控制器时加载的模板作为新的操纵angularjs的模板缓存。

Below should do it. You can manipulate angularjs's template caches by using $templateCache, so $routeProvider will load the template as new every time you access the controller.

myApp.config(function ($routeProvider) {
        $routeProvider.
            when('/', {controller: 'MyCtrl', templateUrl: '/eshop/myConfig'})
})

.controller('MyCtrl', function ($scope, $templateCache) {
    $templateCache.remove('/eshop/myConfig');
    // or
    $templateCache.removeAll();
});

这篇关于Angularjs - 如何清除templateUrl的$ routeProvider的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆