Angular mat select调用仅在鼠标悬停按钮上进行比较
我有一个奇怪的行为,用一个简单的Angular mat select调用仅在鼠标悬停按钮上进行比较,angular,angular-material,Angular,Angular Material,我有一个奇怪的行为,用一个简单的mat select <mat-select [compareWith]="compareFn" placeholder="Options" formControlName="options" multiple> <mat-option *ngFor="let option of options" [value]="option"> {{option.description}} </mat-op
mat select
<mat-select [compareWith]="compareFn" placeholder="Options"
formControlName="options" multiple>
<mat-option *ngFor="let option of options" [value]="option">
{{option.description}}
</mat-option>
</mat-select>
compareFn(c1: OptionModel, c2: string): boolean {
return c1 && c2 ? c1.id === c2 : false;
}
{{option.description}}
compareFn(c1:OptionModel,c2:string):布尔值{
返回c1&&c2?c1.id==c2:false;
}
代码起作用。如果打开“选择、检查选项”,重新加载页面,所有操作都会按预期进行
但是
第一次显示组件时,mat select
显示默认占位符字符串,而不是所选选项。如果将鼠标移到任何组件按钮上,它会神奇地调用compareWith
函数,然后出现值
似乎mouseover
事件唤醒了mat selectcompareWith
,但我不明白为什么!
有人面临过同样的奇怪效果吗