gpt4 book ai didi

Angular 中的 Angular Material mat-select 动态数据绑定(bind)

转载 作者:行者123 更新时间:2023-12-03 22:48:28 24 4
gpt4 key购买 nike

我正在使用 Angular 6 和 Angular Material 。当我单击编辑按钮时,将在选择时初始化辅助值、SSC 和男性值。但我做不到。单击编辑按钮后,我只能在下拉列表中显示男性值。所以我想在下拉列表中显示所有值并传递对象以进行动态选择。谢谢。

我的代码链接在这里:stackblitz link

最佳答案

您可以尝试使用此解决方案

我在 Stackblitz 上创建了一个演示

Component.ts


  editInfo(educationInfo) {
this.education_level = educationInfo.aa;
this.exam_title = educationInfo.bb;
this.gender = educationInfo.cc;
this.educationLevelChangeAction(this.education_level);
}

educationLevelChangeAction(education) {
this.exam_title = "";
let dropDownData = this.educationList.find((data: any) => data.educationLevelName === education);
if (dropDownData) {
this.degreeTitleList = dropDownData.degreeTitleList;
} else {
this.degreeTitleList = [];
}

}

Component.html


<mat-form-field>
<mat-select placeholder="Select Level of Education" name="education_level" (selectionChange)="educationLevelChangeAction(education_level)" [(ngModel)]="education_level" >
<mat-option *ngFor="let education of educationList" [value]="education.educationLevelName" >{{ education.educationLevelName }}</mat-option>
</mat-select>
</mat-form-field>

<mat-form-field>
<mat-select placeholder="Select Exam/Degree Title" name="exam_title" [(ngModel)]="exam_title">
<mat-option *ngFor="let degreeTitle of degreeTitleList" [value]="degreeTitle">{{ degreeTitle }}</mat-option>
</mat-select>
</mat-form-field>

<mat-form-field>
<mat-select [(ngModel)]="gender">
<mat-option *ngFor="let gender of genderList" [value]="gender">{{ gender }}</mat-option>
</mat-select>
</mat-form-field>



<p>You selected: {{education_level}} {{exam_title}} {{gender}}</p>

关于Angular 中的 Angular Material mat-select 动态数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51129116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com