简体   繁体   English

如何在 Angular9 的组件中使用外部 html 文件作为模板?

[英]How to use external html file as template in a component of Angular9?

I am working on a Angular9 application, I have searched all over internet but couldn't find any answer on how to use external html file as template in one of the components.我正在开发一个 Angular9 应用程序,我在互联网上进行了搜索,但找不到关于如何在其中一个组件中使用外部 html 文件作为模板的任何答案。 Can anyone tell me how to do that?谁能告诉我怎么做?

Short answer?简短的回答? it's not possible since the template is processed compile-time (på the IVY compiler).这是不可能的,因为模板是在编译时处理的(通过 IVY 编译器)。

If you want to acquire a template at compile time, I'd create scripting to acquire said template, and replace an existing "dummy" template.如果您想在编译时获取模板,我会创建脚本来获取所述模板,并替换现有的“虚拟”模板。 This scripting needs to run prior to running the ivy compiler (eg. ng build ).此脚本需要在运行 ivy 编译器(例如ng build )之前运行。

The correct (and possible) way of doing it, is to acquire data from an external endpoint, and then present this through a compoennt.正确(并且可能)的做法是从外部端点获取数据,然后通过组件呈现。 That is the way SPAs work.这就是 SPA 的工作方式。

Remember, data can be anything, it can be hard data, but also meta-data (such as colors, layout etc.)请记住,数据可以是任何东西,可以是硬数据,也可以是元数据(例如颜色、布局等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM