Angular - Disable select option if value exists in array -
i have nesting select element in form , want each value selected once. how can check if occupation.occupation
exists in selectedoccupations
array , set [disabled]=''
true if exists?
component
selectedoccupations: any[] = [ { occupation: 'dev' }, ];
template
<tr> <td> <md-select formcontrolname="occupation" [ngmodeloptions]="{standalone: true}" placeholder="occupation" (change)="filterguests($event, i)"> <md-option [value]="null">occupation</md-option> <md-option *ngfor="let occupation of occupationz" [value]="occupation.occupation" [disabled]=""> {{ occupation.occupation }} </md-option> </md-select> </td> </tr>
make call typescript function returns value you!
<tr> <td> <md-select formcontrolname="occupation" [ngmodeloptions]="{standalone: true}" placeholder="occupation" (change)="filterguests($event, i)"> <md-option [value]="null">occupation</md-option> <md-option *ngfor="let occupation of occupationz" [value]="occupation.occupation" [disabled]="isdisabled(occupation)"> {{ occupation.occupation }} </md-option> </md-select> </td> </tr>
and in typescript:
function isdisabled(occupation: any):boolean{ // if exists... disabled == true; return selectedoccupations.includes(occupation.occupation); // note, i'm not if should occupation. }
Comments
Post a Comment