Javascript 在*ng中为angular 2中的循环添加html
我想从angular 2中for循环内的变量添加html代码:Javascript 在*ng中为angular 2中的循环添加html,javascript,angular,Javascript,Angular,我想从angular 2中for循环内的变量添加html代码: <ul> <li *ng-for="#c of myHtmlItems"> {{c.myHtml}} </li> </ul> {{c.myHtml}} html仅作为字符串添加,而不是ng for,请尝试使用ng repeat。因为大多数情况下,重复在非常不同的方面是有用的 <ul> <li ng-r
<ul>
<li *ng-for="#c of myHtmlItems">
{{c.myHtml}}
</li>
</ul>
-
{{c.myHtml}}
html仅作为字符串添加,而不是ng for,请尝试使用ng repeat。因为大多数情况下,重复在非常不同的方面是有用的
<ul>
<li ng-repeat="element in myHtmlItems">
{{element}}
</li>
</ul>
-
{{element}}
尝试使用ng repeat,而不是ng for。因为大多数情况下,重复在非常不同的方面是有用的
<ul>
<li ng-repeat="element in myHtmlItems">
{{element}}
</li>
</ul>
-
{{element}}
您可以执行以下操作:
<ul>
<li *ng-for="#c of myHtmlItems" inner-html="{{c.myHtml}}></li>
</ul>
你可以做:
<ul>
<li *ng-for="#c of myHtmlItems" inner-html="{{c.myHtml}}></li>
</ul>
更新至angular2.0.0
*ng for已替换为*ngFor
#
已替换为let
带innerHTML的内部html
(最好像这样使用属性绑定[innerHTML]='c.myHtml'
,而不是innerHTML=“{{c.myHtml}}
)
更新至angular2.0.0
*ng for已替换为*ngFor
#
已替换为let
带innerHTML的内部html
(最好像这样使用属性绑定[innerHTML]='c.myHtml'
,而不是innerHTML=“{{c.myHtml}}
)
DOM元素可以在Angular 2中重复ng repeat?您的代码仍然有*ng,因为它来自angular版本1。DOM元素可以在angular 2中用ng repeating repeat重复吗?您的代码仍然有*ng,因为它来自angular版本1。这可以工作,但会删除子节点中已经存在的所有其他html。您可以在li,eq.div中创建元素并设置其内部html。li有其他标记(x3dom),并且仅作为示例提到。但它现在起作用了。谢谢。在alpha.52中,ng for变成了ngForthis works,但删除了子节点中已经存在的所有其他html。您可以在li、eq.div中创建元素并设置其内部html。li有其他标记(x3dom),并且仅作为示例提到。但它现在起作用了。谢谢。在alpha.52 ng中变成ngForIn alpha.52 ng中变成ngForIn alpha.52 ng中变成ngForIn alpha.52 ng中变成ngFor