简体   繁体   English

Angular - 创建一个 web 组件并在项目中使用

[英]Angular - creating a web component and using in the project

How can I change one module to a web component and use it in the project?如何将一个模块更改为 Web 组件并在项目中使用它? For example I have 3 modules in the project below and I want to change only module1 to web component and use in the same project?例如我在下面的项目中有 3 个模块,我只想将 module1 更改为 web 组件并在同一个项目中使用?

Thanks谢谢

Source code: https://stackblitz.com/edit/angular-8xwotj源代码: https : //stackblitz.com/edit/angular-8xwotj

In angular currently you can not create a web component of one separate module.在 angular 中,您目前无法创建一个单独模块的 Web 组件。

But here is a work around;-但这里有一个解决办法;-

1) create a duplicate project. 1)创建一个重复的项目。

2) remove all the modules from the project except the one that you wanna use as web component. 2)从项目中删除所有模块,除了要用作 Web 组件的模块。

3) convert duplicate project into the library like this 3)像这样将重复的项目转换成库

4) Lastly, Use that created library in your original project. 4)最后,在您的原始项目中使用创建的库。

I hope this will help you.我希望这能帮到您。 Let me know the results让我知道结果

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

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