简体   繁体   English

Angular 将 HTML 元素添加到动态创建的 HTML 元素

[英]Angular add HTML element to dynamically created HTML element

I have dropdown with items lets say.我有下拉项目可以说。

<customDropdown>
   <item label="ITEM1"></item>
   <item label="ITEM2"></item>
   <item label="ITEM3"></item>
</customDropdown>

This dropdown created new div with class for each item.此下拉菜单为每个项目创建了带有 class 的新 div。 Problem is that I need to add button to items but because is custom dropdown I can pass value only through label which is string.问题是我需要向项目添加按钮,但因为是自定义下拉列表,我只能通过字符串 label 传递值。 Basically I need to do something like基本上我需要做类似的事情
<item label="<button>DELETE</button>ITEM1></item>"
But I cant because its automatically converted to string.但我不能,因为它会自动转换为字符串。

Thanks for any ideas.感谢您的任何想法。

which library are you using?你在使用哪个库? its not possible to pass html element through attribute like that.它不可能通过这样的属性传递 html 元素。 if your library allows you to do such thing its either using <ng-content> ( and if that is the case your implementation would be: <item> <button> delete </button> </item> ) or using custom templates.如果您的库允许您使用<ng-content> (如果是这种情况,您的实现将是: <item> <button> delete </button> </item> )或使用自定义模板。

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

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