Komal Kadam
Komal Kadam

Reputation: 21

Default checked option in primeng multiselect

I am trying to select one option by default using primeng multiselect(angular 7). I am able to select 1 option by default but check box for that option is not getting checked but it's coming in my selected option array. I am displaying that default option as defaultLable on label field of primeng multiselect just for look ad feel. Any one has nay idea how we can make checkbox checked for default selected option.

I tried to put item in to select Array initially, and then displayed using defaultLable

Upvotes: 1

Views: 6172

Answers (1)

Eliseo
Eliseo

Reputation: 57939

just give as value of the multiselect an array with the first value. from the docs

<p-multiSelect [options]="cars" [(ngModel)]="selectedCars" 
      [panelStyle]="{minWidth:'12em'}">
</p-multiSelect>

cars = [
    {label: 'Audi', value: 'Audi'},
    {label: 'BMW', value: 'BMW'},
    {label: 'Fiat', value: 'Fiat'}
]
selectedCars=[cars[0].value]

Upvotes: 3

Related Questions