angular - 当列表初始化为空时,使用 ngFor 创建 mat-option 元素
问题描述
当我在我的“能力”mat-select 中选择一项技能时,我想更新“specialisation”mat-select”中的值。我将我的 var 与使用的模型相关联,[(ngModel)]
但它不会更新列表。
我尝试使用具有角度和材料 7 的 ngModel。
HTML:
<mat-form-field>
<mat-select name="competence_1_name" [(ngModel)]="competence_1.name">
<mat-option>-- Faites un choix --</mat-option>
<mat-option *ngFor="let competence of competences" value="{{competence.name | lowercase}}">{{competence.name}}</mat-option>
</mat-select>
<mat-label>Compétence</mat-label>
</mat-form-field>
[...]
<mat-form-field>
<mat-select name="competence_1_spe_1" [(ngModel)]="competence_1.specialisation_1">
<mat-option>-- Faites un choix --</mat-option>
<mat-option *ngFor="let specialisation of competence_1.specialisation_list" value="{{specialisation | lowercase}}">{{specialisation}}</mat-option>
</mat-select>
<mat-label>Spécialisation</mat-label>
</mat-form-field><br>
主类:
export class GeneratePnjComponent implements OnInit {
competences: Array<Competence>;
masteries: Array<string>;
competence_1 = new Competence("");
competence_2 = new Competence("");
competence_3 = new Competence("");
name: string;
cost: number;
time: number;
...
}
技能等级:
export class Competence {
name: string;
mastery: string;
specialisation_1: string;
specialisation_2: string;
specialisation_list: Array<string>;
constructor(name: string) {
this.name = name;
this.specialisation_list = new Array<string>();
}
}
预期结果:当我在列表“competence_1_name”上选择一个值时,列表“competence_1_spe_1”会更新
实际结果:即使我在列表 'competence_1_name' 中选择一个值,列表 'competence_1_spe_1' 中也没有值
解决方案
推荐阅读
- html - 使用网页的VLC插件,如何在切换视频时保留上一个视频的最后一帧?
- javascript - 是否可以通过javascript中的链接自动下载文件?
- c# - 如何发送 MimeMessage
- asp.net - 如何使用 ASP.NET 和 JSON 调用 C# 代码
- python - 如何使用 split 函数在 python 中拆分单个列表的子列表?
- laravel - 如何使用数据库上的默认数字减少数字
- angular - 如何将数据从 ag 网格传递到打字稿?
- python - 使用 LXML 返回标题文本
- f# - 在 F# 中,匹配表达式能否“通过”另一个匹配?就像在 C# 或 C++ 中一样?
- python - 如何对单词搜索的结果进行编码以计算单词的出现次数