gpt4 book ai didi

javascript - 在 Angular 2 的 *ng-for 循环中添加 html

转载 作者:行者123 更新时间:2023-11-30 09:55:33 26 4
gpt4 key购买 nike

我想在 Angular 2 的 for 循环中从变量中添加 html 代码:

<ul>
<li *ng-for="#c of myHtmlItems">
{{c.myHtml}}
</li>
</ul>

html 仅作为字符串添加

最佳答案

更新到angular2.0.0

<ul>
<li *ngFor="let c of myHtmlItems" [innerHTML]='c.myHtml'></li>
</ul>
  1. *ng-for 已替换为 *ngFor
  2. # 已替换为 let
  3. inner-html 和 innerHTML(最好使用这样的属性绑定(bind) [innerHTML]='c.myHtml' 而不是 inner-html="{{c.myHtml}}})

关于javascript - 在 Angular 2 的 *ng-for 循环中添加 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34199200/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com