0
votes

I am using PrimeNG to render my dynamic dropdown options. Based on the option value I don't want my ngModel to be udpated.

Let's say if my option is an object such as dropdownObject.canUpdateModel = true, then I want my ngModel to be updated, if not ngModel should not be updated. Can someone please help me with this.

<p-dropdown #dp [options]="myList"(onChange)="onFMyDropdownChange(selectedForeCast)"[(ngModel)]="selectedForeCast"></p-dropdown>
1

1 Answers

2
votes

Use getter/setter approach, so you will be able to intercept attempt to set new value to model - inspect the value for given criteria - and assignt to model or reject the change.

It would be something like this

get selectedForeCast(){
   return whateverModelValue;
}

set selectedForeCast(selectedValue){
   if(selectedValue whatever here){
     whateverModelValue=selectedValue;
 }
}