Angular-CLI/Angular2:非标准字符只能在index.html中正确加载,而不能通过ng serve在组件中正确加载 [英] Angular-CLI/Angular2: Non-standard chars only load correctly in index.html, not in components via ng serve

查看:59
本文介绍了Angular-CLI/Angular2:非标准字符只能在index.html中正确加载,而不能通过ng serve在组件中正确加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Angular2应用程序中:当我使用"ng serve"或"ng build"时,扩展字符在组件中无法正确呈现.直接在index.html中扩展字符可以正常工作.

In my Angular2 App: when I use "ng serve" or "ng build" extended characters are not rendered correctly in the Components. Extended chars directly in index.html work fine.

我怀疑这与保存和提供文件的方式有关,但是我对ng2,webpack和CLI还是陌生的,所以还不确定如何测试该理论.

I suspect it is something to do with the way the files are being saved and served but I am new to ng2, webpack and CLI so not really sure how to test that theory just yet.

index.html中的字符集设置为"charset = UTF-8",如果在浏览器中捆绑浏览之前查看单个组件HTML页面,则会正确呈现.

The charset in index.html is set to "charset=UTF-8" and if I view the individual component HTML page BEFORE bundling in the browser it renders correctly.

复制步骤:

  • 将Próximamente"复制并粘贴到Index.html输出区域以及组件模板中.
  • 运行"ng-serve".
  • index.html中的一个将正确呈现,但模板中的一个将无法呈现
  • 注意:部署的产品构建输出也会发生同样的情况

版本

  • Chrome:53.0.2785.143 m
  • 角度:2.1.0
  • Windows:10
  • Webpack:2.1.0 Beta 25
  • Angular-CLI:1.0.0 Beta 18

推荐答案

确保.ts文件(模板)的内容也用 UTF-8 编码.换句话说,index.htmlcharset应该与所提供文件的实际物理编码相匹配.

Make sure the content of .ts files (templates) is also encoded in UTF-8. In other words - the index.html's charset should match the real physical encoding of served files.

PS:您可以在文本编辑器 MS VSC Notepad ++ file -i *等中轻松检查实际编码.

PS: You can easily check actual encoding in text editors MS VSC, Notepad++, file -i *, etc.

这篇关于Angular-CLI/Angular2:非标准字符只能在index.html中正确加载,而不能通过ng serve在组件中正确加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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