You need to publish the event as an @Output
from you md-tab
component. 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 that event in the 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;
}
}
Heres a working plunker that demonstrates the concept
tabChanging
event to indicate the tab has just been clicked - to allow you to prepare for the change. This really ought to be a feature request :-) Like a 'tabGuard' similar to a lightweight route guard. – Jenette