Dynamically Rendering Components in the TabStrip
Environment
| Product | Progress® Kendo UI for Angular TabStrip |
Description
How can I dynamically render a different component in each of the TabStrip tabs? I want to ensure that each tab contains different content in the form of a component, which is rendered upon user interaction.
Solution
To dynamically render components in the TabStrip:
-
Create a wrapper component that contains an
ng-templateelement and use thecreateComponent()method to create the specific component. -
Use the
@forcontrol flow syntax to iterate over the collection of tabs together with the built-inTabContentDirectiveto render custom content in each tab.html@for (item of items; track item; let i = $index) { <kendo-tabstrip-tab ...> <ng-template kendoTabContent #tabContent> ... </ng-template> </kendo-tabstrip-tab> } -
Render the custom wrapper component within the
TabContentDirectiveand provide the specific component that should be displayed.html<my-wrapper [component]="item.component"></my-wrapper>
The following example demonstrates the full implementation of the suggested approach.