Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import { Component, ContentChildren, QueryList, AfterContentInit } from '@angular/core';
import {TabComponent} from "../tab/tab.component";
selector: 'tabs',
<ul class="nav nav-tabs">
<li *ngFor="let tab of tabs" (click)="selectTab(tab)" []="">
<a href="#">{{tab.title}}</a>
export class TabsComponent implements AfterContentInit {
@ContentChildren(TabComponent) tabs: QueryList<TabComponent>;
// contentChildren sont maintenant settés
ngAfterContentInit() {
// recupère les tabs actifs
let activeTabs = this.tabs.filter((tab)=>;
// Activer le premier s'il n'en existe pas
if(activeTabs.length === 0) {
selectTab(tab: TabComponent){
// desactive tous les tabs
this.tabs.toArray().forEach(tab => = false);
// Active le tab sur lequel l'utilisateur à cliqué = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment