【发布时间】:2020-01-08 03:08:45
【问题描述】:
我正在尝试从数组中生成按钮列表:
<div class="card-container">
<mat-button-toggle *ngFor="let button of buttonsFromApi" id={{button.id}} class="problemButton" [disabled]="sso.invalid" >{{button.id}}</mat-button-toggle>
</div>
buttonsFromApi 包含 5 个对象,例如:
{
displayName: "Button name",
id: "100",
}
所以基本上我希望按钮显示displayName(这可行)并具有对象中的ID。后者不会发生,而是按钮具有像100-button 和200-button 这样的ID,而不是100 和200。为什么会这样,我怎样才能使它成为100和200而不是100-button和200-button?
【问题讨论】:
-
也许它是
id属性的值。如果你将<pre>{{ button | json }}</pre>放在循环中 - 你会看到什么? -
我不知道该怎么做 - 你的意思是
<mat-button-toggle *ngFor="let button of buttonsFromApi" <pre>{{ button | json }}</pre> [attr.id]="button.id" >{{button.displayName}}</mat-button-toggle>吗? ` -
作为另一个元素。例如,将其粘贴到
<mat-button-toggle>旁边。甚至代替它。 -
您必须在应用程序的某处附加
-button。 -
我不是但
mat-button-toggle可能...
标签: javascript angular ngfor