在 Angular-CLI 中,车把 运行 何时发生以及 HTML 模板插值何时发生?

In Angular-CLI, when does handlebars run and when does HTML template interpolation happen?

我是所有这些方面的初学者(Angular-2、Angular-CLI、Handlebars、Web 2.0 开发)。我刚开始使用 Angular-2/CLI,我注意到一些令人困惑的事情。在 Angular-CLI 生成的项目中,在 index.html 中,我看到了这个:

{{#each scripts.polyfills}}
<script src="{{.}}"></script>
{{/each}}

我猜哪个是由 Handlebars 以某种方式处理的?

那么,Angular-2 的插值会发生什么,它也使用 {{...}}

我是否必须以某种方式转义卷曲,或者 Handlebars 是否只处理某些文件,或者什么?

TL;DR:您可以忽略该语法,无需转义任何内容。

说明: 当你 运行 ng build(或类似的)时,你的 index.html 被解析并且生成的文件保存在 /dist 中。 该文件随后会提供给浏览器,并且不包含 {{...}} 部分。 所以与Angular的插值完全没有冲突,你不需要转义任何东西。

CLI 确实在内部使用了 Handlebars,但唯一解析的文件是 index.html as you can see in the source code.

另请注意,在即将发布的使用 webpack 的 angular-cli 版本中,此语法将完全消失。 (您现在已经可以 use the master branch 试用了)

仅供参考,Github 上也对此进行了讨论: https://github.com/angular/angular-cli/issues/993