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

标签 javascript angular typescript

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

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

相关文章:

javascript - Jquery下拉菜单垂直

JavaScript 代码适用于 IE,但不适用于 Safari(Mac 或 Windows)

css - 增加以 Angular 6 减小整个应用程序的字体大小

angular - ionic 应用程序中的循环依赖

javascript - 回发后如何显示成功和错误消息?

javascript - 如果主窗口隐藏,router.push electro-vue 将不起作用

node.js - node_modules/ng2-toastr/src/toast-container.component.d.ts(1,48) : TS2305-/node_modules/@angular/core/core"' has no exported member 中的错误

typescript - 是否可以实现 Y-combinator 的 TypeScript 通用版本?

typescript - Angular2 将属性传递给类构造函数

javascript - Sequelize 创建不止一个记录问题