/**
* The main component that renders single TabComponent
* instances.
*/
import {
Component,
ContentChildren,
QueryList,
AfterContentInit, Output, EventEmitter,
} from '@angular/core';
import { TabComponent } from './tab.component';
@Component({
selector: 'my-tabs',
template: `
`//,
// styles: [
// `
// .tab-close {
// color: gray;
// text-align: right;
// cursor: pointer;
// }
// `
// ]
})
export class TabsComponent implements AfterContentInit {
@ContentChildren(TabComponent) tabs: QueryList;
@Output() public selectedActiveTab: EventEmitter = new EventEmitter();
// contentChildren are set
ngAfterContentInit() {
// get all active tabs
let activeTabs = this.tabs.filter((tab)=>tab.active);
console.log("ACTIVE TABS: "+activeTabs.length);
// if there is no active tab set, activate the first
if(activeTabs.length === 0) {
this.selectTab(this.tabs.first);
}
}
selectTab(tab: TabComponent){
// deactivate all tabs
this.tabs.toArray().forEach(tab => tab.active = false);
// activate the tab the user has clicked on.
tab.active = true;
console.log("ACTIVE TAB SET TO: "+tab.title);
this.selectedActiveTab.emit(tab.tabId);
}
}