簡體   English   中英

在角度2的* ng-for循環中添加html

[英]Add html in *ng-for loop in angular 2

我想從角度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. 帶innerHTML的inner-html(最好使用像[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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM