/** * The main component that renders single TabComponent * instances. */ import { Component, ContentChildren, QueryList, AfterContentInit, Output, EventEmitter, ViewChild, ElementRef, } from '@angular/core'; import { TabComponent } from './tab.component'; declare var UIkit: any; @Component({ selector: 'my-small-tabs', template: `
` }) export class SmallTabsComponent implements AfterContentInit { @ViewChild('drop_element') dropElement: ElementRef; @ContentChildren(TabComponent) tabs: QueryList; @Output() public selectedActiveTab: EventEmitter = new EventEmitter(); public activeTabs: TabComponent[] = []; // contentChildren are set ngAfterContentInit() { // get all active tabs this.activeTabs = this.tabs.filter((tab)=>tab.active); // if there is no active tab set, activate the first if(this.tabs.length > 0 && this.activeTabs.length === 0) { this.selectTab(this.tabs.first); } } selectTab(tab: TabComponent){ console.log("selectTab: "+tab.title); // deactivate all tabs this.tabs.toArray().forEach(tab => tab.active = false); this.activeTabs = []; this.activeTabs.push(tab); // activate the tab the user has clicked on. tab.active = true; this.selectedActiveTab.emit(tab.tabId); if(this.dropElement) { console.log("dropElement: ",this.dropElement); UIkit.drop(this.dropElement.nativeElement).hide(false); } } }