Wrapping the MultiSelect in a Custom Component with the Item Template
Environment
Product | Progress® Kendo UI® for Angular MultiSelect |
Description
How can I wrap the MultiSelect into a custom component and modify its items with the built-in ItemTemplateDirective
?
Solution
To wrap the MultiSelect in a custom component and customize the items through the ItemTemplateDirective
:
-
Define the MultiSelect along with its
ItemTemplateDirective
. To customize the items from the custom wrapper component, define theng-container
tag inside the template and configure theNgTemplateOutlet
.html<kendo-multiselect [data]="listItems"> <ng-template kendoMultiSelectItemTemplate let-dataItem> <ng-container *ngTemplateOutlet="currentTemplate; context: { $implicit: dataItem }"></ng-container> </ng-template> </kendo-multiselect>
-
The
currentTemplate
is a custom field which represents theTemplateRef
provided by the custom wrapper component.ts@Input() initialTemplate: TemplateRef<any>; currentTemplate: TemplateRef<any>; ngOnInit() { this.currentTemplate = this.initialTemplate; }
-
In the custom wrapper component, define an
ng-template
and pass the template reference variable to the custominitialTemplate
field.html<app-multi-select [initialTemplate]="save"> </app-multi-select> <ng-template #save let-dataItem> {{dataItem.text}} </ng-template>
The following example demonstrates how to wrap the MultiSelect component and customize its items by using an external template.