#15277·primeng

multiselect: selectedOptions within selectedItemsTemplate not cleared

Author: capc0Created Apr 15, 2024Updated Sep 21, 2026
LabelsType: Bug

Describe the bug

When using a multiselect with selectedItemsTemplate template, the internal selectedOptions variable is not always cleared correctly. Therefore a previous value is still rendered within the multiselect.

Unfortunatly I am currently not able to reproduce this within a stackblitz issue template, but the problem is that the internal selectedOptions variable is not cleared when the modelValue and visibleOptions is set to an empty array [].

Because visibleOptions is empty here https://github.com/primefaces/primeng/blob/master/src/app/components/multiselect/multiselect.ts#L1122, the variable selectedOptions is not updated and still has dirty state.


As a workaround the following can be added:

typescript
else if (this.selectedOptions?.length > 0) {
                this.selectedOptions = [];
                this.cd.markForCheck();
}

I believe the bug was introduced with issue https://github.com/primefaces/primeng/issues/14187

Environment

Latest

Reproducer

https://stackblitz.com/edit/github-8p6qdv?file=src%2Fapp%2Fapp.component.html

image

Angular version

17

PrimeNG version

17.13.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response