I'm attempting to make a reusable tab component and am confused about how to iterate over multiple ContentChildren
(corrected) within the component to wrap them in html.
I've got a component in my view
<demo-tabs>
<a routerLink="/some/link">Tab 1</a>
<a routerLink="/some/other/link">Tab 2</a>
<a routerLink="/some/third/link">Tab 3</a>
</demo-tabs>
which I'd like to render like so:
<ul>
<li><a routerLink="/some/link">Tab 1</a></li>
<li><a routerLink="/some/other/link">Tab 2</a></li>
<li><a routerLink="/some/third/link">Tab 3</a></li>
<ul>
It doesn't seem like I can embed content in ng-content
which is what I tried first, and the following template blows up with ExpressionChangedAfterItHasBeenCheckedError
@Component({
selector: 'demo-tabs',
template: `<ul class="tabs">
<li *ngFor="let a of links">
{{a}}
</li>
</ul>`})
export class TabsComponent implements OnInit {
@ContentChildren('a') links: TemplateRef<any>; // corrected. I originally had this as @ViewChildren
constructor() { }
ngOnInit() {
}
}