i am trying to disable option in p-dropdown but i use ng-template for looping the options
here is my code
any suggestions ?
thanks
<p-dropdown
[options]="task.statusOptions"
optionLabel="name"
optionValue="id"
(onChange)="updateTaskCurrentStatus($event, task)"
appendTo="body"
[placeholder]="this.dropdownPlaceholder(task)"
>
<ng-template let-status pTemplate="status">
<div [ngStyle]="{ color: status.uiSetting.color}" [ngClass]="{'pointer-events-none': status.enabled}">{{ status.name }}</div>
</ng-template>
</p-dropdown>
2
Answers
Ok so the only thing need to be done is to add disable key to each object display on the loop(without nothing else need in html)i actually saw this on other question and by mistake put the disabled key in the wrong place(thought maybe looping it in the ng-template having effect on it) so case close thanks for all the answers !
You can configure a property
disabled
which will contain the flag to disable the option, then we can use[optionDisabled]="'disabled'"
to set the property that disables the option.The object contains the flag that disables it.
Full Code:
Stackblitz Demo