question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Tabs] Get label property of selected tab

See original GitHub issue

Bug, feature request, or proposal:

Feature Request

What is the expected behavior?

To programmatically get the name of the currently selected tab

What is the current behavior?

It seems that (selectedTabChange) and md-on-select aren’t executing the ts code for some reason. Even if they did, they would only return the current index #. I need the full value of the label property for what I’m working with.

What are the steps to reproduce?

<md-tab-group (selectedTabChange)="tabChanged($event)" style="margin-top:16px;">
      <md-tab label="{{ thing.name }}" *ngFor="let thing of things | async">

        <div class="ui basic segment">
          <table class="ui three column center aligned table">
            <thead>
              <tr>
                <th><div class="ui pink button">Item 1</div></th>
                <th><div class="ui pink button">Item 2</div></th>
                <th><button class="ui red button"><i class="pin icon"></i>Pinned</button></th>    
              </tr>
            </thead>
          </table>
        </div>

      </md-tab>
      <md-tab label="+ Add Thing"></md-tab>
    </md-tab-group>

What is the use-case or motivation for changing an existing behavior?

In this example, I would add an item to the tabs list. Then when clicked, I would find the value of the selected tab’s label property to see which tab is selected and therefore which information to load from my Firestore database. The path in my database that I need to load is given the same value as the label property of the tab, which makes it much easier to work with.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

AngularFire2 v5 Angular Common v4.2.4 Material v2.0.0 beta.10 Typescript v2.3.3

Is there anything else we should know?

Platypus are from the same family as Echidnas.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18

github_iconTop GitHub Comments

3reactions
FiringBlankscommented, Oct 23, 2017

The selectedTabChange property only fires when a tab is changed. That’s good, but Is there a way of getting the name of the tab that is set when the mat-tab-group is first initialized?

I tried setting @ViewChild('tabGroup') tabGroup and running the ngAfterViewInit() function below but that only gets me the index of the tab set on initialization (which is always 0). I need the actual label again.

ngAfterViewInit() {
    console.log('afterViewInit => ', this.tabGroup.selectedIndex); 
  }
1reaction
ATakaSKYcommented, Mar 15, 2018

@FiringBlanks Found the solution. You can do: this.tabGroup._tabs.first.textLabel on the tabGroup instance from ViewChild.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get the active tab In Angular Material2
Yes, the label, but I want to get it when the tab-group is first initialized, not listen for when the tabs are changed...
Read more >
Tabs | Angular Material
Supports string and string array values, same as ngClass . Plain text label for the tab, used when there is no template label....
Read more >
formContext.ui.tabs (Client API reference)
It contains properties and methods to manipulate tabs as well as access to sections within the ... getLabel, Returns the label for the...
Read more >
React Tabs component - Material UI
Long labels will automatically wrap on tabs. If the label is too long for the tab, it will overflow, and the text will...
Read more >
Example of Tabs with Automatic Activation | APG | WAI
Role, Property, State, and Tabindex Attributes · Removes the element from the page Tab sequence. · Set when a tab is not selected...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found