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

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

问题描述

我的应用程序中有非常基本的用例,其中前端使用AngularJS(1.0.8),后端使用Grails.在应用程序布局中,我有一个语言切换器,允许用户更改语言.切换语言后,它会发出新的http请求以检索页面.Grails会正确翻译所有与语言相关的内容(即标签).这仅适用于Chrome,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不会加载 $ routeProvider templateUrl ,因为它是从缓存中加载它们的:

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:

推荐答案

下面应该这样做.您可以使用$ templateCache来操纵angularjs的模板缓存,因此$ routeProvider会在每次访问控制器时将模板作为新模板加载.

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' s缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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