在 angular 2 中的 *ng-for 循环中添加 html
Add html in *ng-for loop in angular 2
我想在 angular 2:
中的 for 循环内添加来自变量的 html 代码
<ul>
<li *ng-for="#c of myHtmlItems">
{{c.myHtml}}
</li>
</ul>
html 仅作为字符串添加
尝试使用 ng-repeat,而不是 ng-for。由于大多数 ng-repeat 以非常不同的方式有用
<ul>
<li ng-repeat="element in myHtmlItems">
{{element}}
</li>
</ul>
你可以这样做:
<ul>
<li *ng-for="#c of myHtmlItems" inner-html="{{c.myHtml}}></li>
</ul>
更新到angular2.0.0
<ul>
<li *ngFor="let c of myHtmlItems" [innerHTML]='c.myHtml'></li>
</ul>
- *ng-for 已替换为 *ngFor
#
已替换为 let
- inner-html with innerHTML
(最好使用 属性 这样的绑定
[innerHTML]='c.myHtml'
而不是 inner-html="{{c.myHtml}}
)
我想在 angular 2:
中的 for 循环内添加来自变量的 html 代码<ul>
<li *ng-for="#c of myHtmlItems">
{{c.myHtml}}
</li>
</ul>
html 仅作为字符串添加
尝试使用 ng-repeat,而不是 ng-for。由于大多数 ng-repeat 以非常不同的方式有用
<ul>
<li ng-repeat="element in myHtmlItems">
{{element}}
</li>
</ul>
你可以这样做:
<ul>
<li *ng-for="#c of myHtmlItems" inner-html="{{c.myHtml}}></li>
</ul>
更新到angular2.0.0
<ul>
<li *ngFor="let c of myHtmlItems" [innerHTML]='c.myHtml'></li>
</ul>
- *ng-for 已替换为 *ngFor
#
已替换为let
- inner-html with innerHTML
(最好使用 属性 这样的绑定
[innerHTML]='c.myHtml'
而不是inner-html="{{c.myHtml}}
)