简体   繁体   中英

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. 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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