Reputation: 1800
HTML:
<select data-placeholder="Skill List" style="width:100%;" class="chzn-select form-control" multiple="multiple">
<option *ngFor="#skill of allSkills" [ngValue]="skill">{{skill}}
</option>
</select>
TS:
allSkills = ['Welding', 'Forklifting'];
selectedSkill = ['Welding'];
ngOnInit(): void {
jQuery('.chzn-select').select2();
}
How to add the selectedSkill initially?
Upvotes: 0
Views: 214
Reputation: 23506
Just add the ngModel
binding to the select
tag:
<select data-placeholder="Skill List"
[(ngModel)]="selectedSkill"
style="width:100%;"
class="chzn-select form-control"
multiple="multiple">
<option *ngFor="#skill of allSkills" [ngValue]="skill">
{{skill}}
</option>
</select>
And in your code:
allSkills = ['Welding', 'Forklifting'];
selectedSkill = allSkills[0]; // or just 'Welding'
ngOnInit(): void {
jQuery('.chzn-select').select2();
}
Upvotes: 1