对Angular 2应用程序进行版本控制

编程入门 行业动态 更新时间:2024-10-12 05:46:19
本文介绍了对Angular 2应用程序进行版本控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

How can one mark versions of an Angular 2 app?

存在一些问题,例如视图(通过templateUrl)在路线视图(子组件)中未得到更新.我已经尝试过类似的事情

There are some problems like views (via templateUrl) are not getting updated in route views (child components). I've tried things like

<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一起玩,但是它不起作用.

Or app/v1/boot and playing with base but it's not working.

注意:仅作记录,在开发时,缓存的模板(通过templateUrl引入)会令人讨厌地变慢.人们应该使用隐身会话或清除浏览器等.我已经通过在export var fileVersion = '?tmplv=' + Date.now();之类的模块中引入全局var并将其用于诸如以下的组件中来解决了此问题:

Note: Just for the record, at development time, cached templates (introduces via templateUrl) do annoyingly slow things. One should use incognito sessions or clear up the browser and the like. I've solved this by introducing a global var in a module like export var fileVersion = '?tmplv=' + Date.now(); and use it in components like:

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

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

So I have just to refresh the browser to see the changes. In production use either fileVersion = ''; or like export var fileVersion = '?tmplv=v3';.

推荐答案

我正在处理同一问题. 我正在寻找类似filerev Node包的东西. 现在,我的解决方案是使用angular 2清除缓存:

I am dealing with the same issue. I am looking for something like filerev Node package. For now, my solution is to use angular 2 to clear the cache:

首先导入RuntimeCompiler.

First import the RuntimeCompiler.

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

接下来将RuntimeCompiler注入您的构造函数中.

Next inject the RuntimeCompiler in your constructor.

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

constructor(private _runtimeCompiler: RuntimeCompiler) Finally use that to clear the cache. Note this clears all templates.

this._runtimeCompiler.clearCache();

更多推荐

对Angular 2应用程序进行版本控制

本文发布于:2023-11-08 06:45:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568636.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   版本   Angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!