You need to post the event as @Output from you md-tab . Something like:
import { EventEmitter, Output, Input, Component } from '@angular/core'; @Component({ selector: 'tab', template: ` <button (click)="clicked()">{{ name }}</button> `, styles: [` `] }) export class TabComponent { @Input() name = 'replaceme'; @Output() tabClicked = new EventEmitter<null>(); clicked() { this.tabClicked.emit(); } }
Then you consume this event in md-tab-group , something like this:
import { Component } from '@angular/core'; @Component({ selector: 'tab-group', template: ` <!--<tab *ngFor="let tab of tabs" [name]="tab"></tab>--> <tab *ngFor="let tab of tabs" [name]="tab" (tabClicked)="tabChanged(tab)"></tab> <div> {{ selectedTab }} </div> `, styles: [` `] }) export class TabGroupComponent { private tabs = ['foo', 'bar']; private selectedTab = this.tabs[0]; onInit() { this.selectedTab = this.tabs[0]; } tabChanged(tab) { this.selectedTab = tab; } }
The working plunker demonstrates the concept.
Lucas
source share