3

如何标记 Angular 2 应用程序的版本?

存在一些问题,例如视图(通过templateUrl)在路由视图(子组件)中没有得到更新。我试过像

<script>
    System.config({
        // baseURL: '/',
        packages: {        
            app: {
                format: 'register',
                defaultExtension: 'js'
            }
        }
    });
    System.import('v1/app/boot')
        .then(null, console.error.bind(console));
</script>

或者app/v1/boot和玩,base但它不工作。

注意:仅作记录,在开发时,缓存的模板(通过 引入templateUrl)会做一些令人讨厌的慢动作。应该使用隐身会话或清除浏览器等。我已经通过在一个模块中引入一个全局变量来解决这个问题,export var fileVersion = '?tmplv=' + Date.now();并在如下组件中使用它:

@Component({
    selector: 'my-component',
    templateUrl: '/app/templates/my-component.html' + fileVersion,
})

所以我只需刷新浏览器即可查看更改。在生产中使用fileVersion = '';或类似export var fileVersion = '?tmplv=v3';

4

1 回答 1

1

我正在处理同样的问题。我正在寻找类似 filerev 节点包的东西。目前,我的解决方案是使用 angular 2 来清除缓存:

首先导入 RuntimeCompiler。

import { RuntimeCompiler} from '@angular/compiler/src/runtime_compiler';

接下来在构造函数中注入 RuntimeCompiler。

constructor(private _runtimeCompiler: RuntimeCompiler) 最后用它来清除缓存。请注意,这会清除所有模板。

this._runtimeCompiler.clearCache();

于 2016-06-27T04:39:08.743 回答