无法使用ngModel和Angular在字符串上创建'selected'属性

问题描述 投票:0回答:1

所以我试图像这样使用[(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。如果有人可以帮助您一点理解这里的问题,会很高兴吗?

html angular angular-ngmodel
1个回答
0
投票

再增加一个属性

© www.soinside.com 2019 - 2024. All rights reserved.