【问题标题】:angular material string-array to pre-multi-selected mat-select to display data in more user-friendly format角度材料字符串数组到预多选垫选择以更用户友好的格式显示数据
【发布时间】:2019-08-14 10:25:18
【问题描述】:

想要在 mat-select 中显示一个字符串数组。该 mat-select 应将数据显示为预选(多个)格式。通过单击它,应显示选项,但不应进行任何更改。 mat-select 是 mat-table 条目的一部分,应该只是在 html-template-code 中定义的 view-cell(不应更改 table-data-source 的数据)。

以angular-material-select-documentation为例,但甚至无法让它显示数据,而无需手动选择。

<ng-container matColumnDef="letters">
  <th mat-header-cell *matHeaderCellDef>Letters</th>
  <td mat-cell *matCellDef="let data; let i = index;">
    <mat-form-field>
      <mat-label></mat-label>
      <mat-select multiple [ngModel]="data.letters">
        <mat-option *ngFor="let letter of data.letters" checked disabled>
          {{letter}}
        </mat-option>
      </mat-select>
    </mat-form-field>
  </td>
</ng-container>

【问题讨论】:

    标签: arrays angular drop-down-menu angular-material mat-table


    【解决方案1】:

    您可以通过将value 添加到选择的模型中来“检查”多选控件中的选项:

    <ng-container matColumnDef="letters">
      <th mat-header-cell *matHeaderCellDef>Letters</th>
      <td mat-cell *matCellDef="let data; let i = index;">
        <mat-form-field>
          <mat-label></mat-label>
          <mat-select multiple [ngModel]="data.letters">
            <mat-option *ngFor="let letter of data.letters" [value]="letter" disabled>
              {{letter}}
            </mat-option>
          </mat-select>
        </mat-form-field>
      </td>
    </ng-container>
    

    【讨论】:

    • 好的,谢谢。您的解决方案解决了我的问题。谢谢你。 :)
    猜你喜欢
    • 1970-01-01
    • 2021-02-17
    • 2020-07-05
    • 2021-11-05
    • 1970-01-01
    • 2018-04-30
    • 1970-01-01
    • 2019-11-26
    • 2021-12-27
    相关资源
    最近更新 更多