Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 380
Ranjith Avatar asked Jun 11 '26 20:06

Ranjith


1 Answers

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>
like image 131
Krishna Rathore Avatar answered Jun 13 '26 11:06

Krishna Rathore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!