我怎样才能实现以下目标:
<mat-select formControlName="ctrlName">
<mat-option *ngFor="let opt of options" [value]="opt.key">
{{opt.label}}
</mat-option>
</mat-select>
<div *ngIf=" SHOW IF A CERTAIN OPTION FROM THE LOOPED LIST ABOVE IS SELECTED "></div>
组件示例列表:
options = [
{ key: 'keyOne', label: 'Key One 1' },
{ key: 'keyTwo', label: 'Key One 2' },
{ key: 'keyThree', label: 'Key One 3' }
]
最佳答案
根据angular material网站(example here),您需要将[formControl]="selected"
添加到mat-select
组件。
<mat-select [formControl]="selected">
<mat-option *ngFor="let opt of options" [value]="opt">
{{option.label}}
</mat-option>
</mat-select>
<div *ngIf="selected===<your_specific_value>"></div>
关于javascript - angular - 基于 mat-select 选项的条件元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51764702/