我需要在循环中以角度附加动态html。
正如我尝试以下列方式使用,但是遇到问题
<div class="reseipt panel panel-default" *ngFor="let goal of goals">
<p class="panel-heading" data-toggle="collapse" data-target="
{{'#collapse-'+ goal.Id}}">
Goal - {{goal.Description}} {{goal.Id}}
</p>
在尝试添加此代码时,我遇到了以下问题:
Can't bind to 'target' since it isn't a known property of 'p'. ("ult" *ngFor="let goal of goals">
请建议我该如何解决此问题。
感谢。
答案 0 :(得分:0)
试试这个
<div class="reseipt panel panel-default" *ngFor="let goal of goals">
<p class="panel-heading" data-toggle="collapse"
[attr.data-target]="'#collapse-'+ goal.Id">Goal - {{goal.Description}} {{goal.Id}}</p>
data-target不是引导程序使用的html5属性。所以Angular给你错误。 more detail
答案 1 :(得分:0)
试试这个
<div class="reseipt panel panel-default" *ngFor="let goal of goals">
<p class="panel-heading" data-toggle="collapse"
[attr.data-target]="'#collapse-'+ goal.Id"> Goal - {{goal.Description}} {{goal.Id}}</p>
要明确告诉Angular使用属性绑定,请使用attr