I am trying to deactivate one or more items according to data. For example, I have a list of cities with disable/active field, for example, and I pushed the city names in a SelectItem[] array.
NewYork, active
Rome, disable
London, active
Istanbul, disable
Paris, active
this.cities.push({label:'New York', value:'New York'});
this.cities.push({label:'Rome', value:'Rome'}); // want to disable
this.cities.push({label:'London', value:'London'});
this.cities.push({label:'Istanbul', value:'Istanbul'}); // want to disable
this.cities.push({label:'Paris', value:'Paris'});
I tried to render the list-box in using primeng example
<p-listbox [options]="cities" [(ngModel)]="selectedCity" filter="filter">
<ng-template let-city pTemplate="item" >
<div class="ui-helper-clearfix">
<span >{{city.value}}</span>
</div>
</ng-template>
</p-listbox>
In primeng, list-box has one attribute called disabled. If I set it then it disabled the whole list-box. But I want to disable only the specific items.
Here is the implemented Plunker https://plnkr.co/edit/7MHSzdmvIWNpdHsEy4F9?p=preview
You could always create a mutator for selectedCity...
private _selectedCity: string;
private set selectedCity(city:string) {
if(isactive){... do stuff ...}
}
However obviously this might not be great for user experience as the item would still be clickable.