Question 1 / 1
A TabsetComponent uses @ContentChildren(TabComponent) to query projected tabs. In ngOnInit, it tries to activate the first tab. In ngAfterContentInit, the same code works correctly. Why does it fail in ngOnInit?
typescript export class TabsetComponent implements OnInit, AfterContentInit { @ContentChildren(TabComponent) tabs: QueryList<TabComponent>;
ngOnInit(): void { console.log(this.tabs.length); // logs 0 this.tabs.first?.isActive = true; // does nothing }
ngAfterContentInit(): void { console.log(this.tabs.length); // logs 3 this.tabs.first.isActive = true; // works correctly } }