简体   繁体   中英

Disabling mat-select in Angular

I have a dropdown. I want to disable the entire mat-select when the selected value is Uber . Otherwise, it needs to be enabled.

<mat-label>DB Property Name</mat-label>

<mat-select class="dBProperty"  name="dbpropertyName{{i}}" [(ngModel)]="mappingObj.dbpropertyName" [disabled]="selectedValue=='**Uber**'?'disabled':'null'" required>

<mat-option *ngFor="let options of dBPropertyArray" [value]="options.dBProperty" >{{options.dBProperty}}
                                                    </mat-option>

                                                </mat-select>

How can I achieve it..? This is my code. where am I going wrong?

use disabled attribute for that.

<mat-select 
    class="dBProperty" 
    name="dbpropertyName{{i}}" 
    [(ngModel)]="mappingObj.dbpropertyName"
    [disabled]="mappingObj.dbpropertyName=='Uber'"
    required>

    <mat-option *ngFor="let options of dBPropertyArray" [value]="options.dBProperty">{{options.dBProperty}}
    </mat-option>

</mat-select>

The below change will fix your issue. disabled property accepts boolean values. If true its disabled else enabled.

[disabled]="selectedValue=='Uber'"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM