I have the following code:
<md-tab-group (selectChange)="doSomething()">
<md-tab *ngFor="let p of something))">
<template md-tab-label>
{{p.name}} ...
</template>
</md-tab>
</md-tab-group>
Now doSomething() get's fired on Tab-Change and I can access the selected Index, but is there any way to access values of my *ngFor loop? I'd need 'p.id' in my code to fetch data from my database, depending on the open tab. Or is there a much more elegant solution I am not thinking of? Thanks for any help :)
For anyone interested, I solved my problem this way:
<md-tab-group #tabgroup (selectChange)="doSomething(tabgroup)"> <md-tab *ngFor="let p of something" [attr.data-pid]="p.id"> <template md-tab-label> {{p.name}} ... </template> </md-tab> </md-tab-group>
doSomething(tabgroup: MdTabGroup) { let pid = tabgroup._tabs.find((e, i, a) => i == tabgroup.selectedIndex) .content.viewContainerRef.element.nativeElement.dataset.pid; console.log(pid); }