我想要获取我选择的选项的选项文本,同时也要获取选项值。我需要在下面的代码中进行哪些必要的更改?
<mat-select (selectionChange)="changeQuestionValue($event.value)">
  <ng-container *ngFor="let q of QuestionCategory">
    <mat-option *ngIf="q.isActive" [value]="q.id">{{ q.questionCategoryName }}</mat-option>
  </ng-container>
</mat-select>TS
changeQuestionValue(val) {
    return this.questionValue = val;
}这里TS只接收q.id,但我也想要q.questionCategoryName。
发布于 2020-07-02 04:18:21
我觉得你应该换掉[value]="q"
<mat-select (selectionChange)="changeQuestionValue($event.value)">
  <ng-container *ngFor="let q of QuestionCategory">
    <mat-option *ngIf="q.isActive" [value]="q">{{ q.questionCategoryName }}</mat-option>
  </ng-container>
</mat-select>发布于 2020-07-02 04:25:37
你需要替换
value="q“
至
Value=“{{q}”
https://stackoverflow.com/questions/62688705
复制相似问题