所以我试图像这样使用[(ngModel)]
:
<div class="items">
<tbody>
<tr *ngFor="let account of this.accounts">
<td>
<input type="checkbox" [(ngModel)]="this.account.name.selected" name="account">
{{account.name}}
</td>
</tr>
</tbody>
</div>
我的accounts
已创建并填写在组件中:accounts: Account[] = [];
我的Account
对象:
export class Account {
name: string;
surname: string;
}
我正在获取ERROR TypeError: Cannot create property 'selected' on string 'John'
[我看到了这个线程:Cannot create property 'selected' on string 'Information Technology' angularjs,但是不太了解如何将提到的修复程序应用于我的案例,这可能是因为我使用的是Angular而不是AngularJS。如果有人可以帮助您一点理解这里的问题,会很高兴吗?
再增加一个属性