I have such nested ng-template structure.
@Component({
selector: 'my-app',
template: `
<list>
<ng-template *ngFor="let item of Items" #ListItem>
<ng-template #ListItemLine>{{ item[0] }}</ng-template>
<ng-template #ListItemLine>{{ item[1] }}</ng-template>
<ng-template #ListItemLine>{{ item[2] }}</ng-template>
I can see this line, but can't get above templates
</ng-template>
</list>
`,
})
export class App {
Items: Array<Array<string>> = [
[ "1-1", "1-2", "1-3", ],
[ "2-1", "2-2", "2-3", ],
[ "3-1", "3-2", "3-3", ],
[ "4-1", "4-2", "4-3", ],
[ "5-1", "5-2", "5-3", ],
]
}
How can I render children ng-component in my component:
@Component({
selector: 'list',
template: `
<ul>
<li *ngFor="let item of Items">
<ng-container *ngTemplateOutlet="item"></ng-container>
</li>
</ul>
`,
})
export class ListComponent {
@ContentChildren('ListItem') public Items;
}
Plunkr https://plnkr.co/edit/Hi1ZqPAAYyIbclUuzRrl?p=preview
Thank you in advance.
Update
At the end I want to wrap Angular Material components into my components, so if I would find a btter UI than Material, I shouldn't have to change all accurances of Material components in my program, I would just need to change implementation of my wrapper UI components.
For exmple let's try to wrap mat-list component. I need to make a wrapper for mat-list container, let's call it my-list:
@Component({
selector: 'my-list',
template: `
<mat-list>
<ng-content></ng-content>
</mat-list>
`,
})
and a wrapper for mat-list-item:
@Component({
selector: 'my-list-item',
template: `
<mat-list-item>
<ng-content></ng-content>
</mat-list>
`,
})
The HTML render result would be:
- my-list
- mat-list
- my-list-item
- mat-list-item
- ...
- my-list-item
- mat-list
Each Material component surrounded by my wrapper, so directives and styles which come with Material will not work.