[英]Add html in *ng-for loop in angular 2
我想從角度2的for循環內的變量添加html代碼:
<ul>
<li *ng-for="#c of myHtmlItems">
{{c.myHtml}}
</li>
</ul>
html僅作為字符串添加
<ul>
<li *ngFor="let c of myHtmlItems" [innerHTML]='c.myHtml'></li>
</ul>
#
已替換為let
[innerHTML]='c.myHtml'
這樣的屬性綁定,而不要使用inner-html="{{c.myHtml}}
)) 你可以做:
<ul>
<li *ng-for="#c of myHtmlItems" inner-html="{{c.myHtml}}></li>
</ul>
嘗試使用ng-repeat代替ng-for。 由於大多數ng-repeat的用法非常不同
<ul>
<li ng-repeat="element in myHtmlItems">
{{element}}
</li>
</ul>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.