Reputation: 3181
I am using the multiselect module from PrimeNG
.I am copying the following code from the documentation:
export class AppComponent {
title = 'DataShit';
cities1: SelectItem[];
cities2: City[];
selectedCities1: City[];
selectedCities2: City[];
constructor() {
//SelectItem API with label-value pairs
this.cities1 = [
{label: 'New York', value: {id: 1, name: 'New York', code: 'NY'}},
{label: 'Rome', value: {id: 2, name: 'Rome', code: 'RM'}},
{label: 'London', value: {id: 3, name: 'London', code: 'LDN'}},
{label: 'Istanbul', value: {id: 4, name: 'Istanbul', code: 'IST'}},
{label: 'Paris', value: {id: 5, name: 'Paris', code: 'PRS'}}
];
//An array of cities
this.cities2 = [
{name: 'New York', code: 'NY'},
{name: 'Rome', code: 'RM'},
{name: 'London', code: 'LDN'},
{name: 'Istanbul', code: 'IST'},
{name: 'Paris', code: 'PRS'}
];
}
}
Now I am rendering the cities2
using the following markup in my component.
<p-multiSelect [options]="cities2" [(ngModel)]="selectedCities2" defaultLabel="Select your city">
<ng-template let-city pTemplate="item">
{{city.name}}
</ng-template>
</p-multiSelect>
Now my question is: Can i precheck some of this checkboxes based on some conditions?(E.g.: cities that start with 'S' or a different filter)
Upvotes: 0
Views: 1310
Reputation: 86800
Yes, You can.
You need to bind your selected data with [(ngModel)]="selectedCities2"
, this will allow you to show pre selected data filled in multiselect.
For example -
selectedCities2 = ['NY', 'RM'];
Upvotes: 1