gpt4 book ai didi

javascript - angular - 基于 mat-select 选项的条件元素

转载 作者:行者123 更新时间:2023-11-30 08:22:05 26 4
gpt4 key购买 nike

我怎样才能实现以下目标:

<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/

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