Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using mat-tabs with ngFor, Initializing component twice #16397

Open
ssahu123 opened this issue Jun 27, 2019 · 3 comments
Open

Using mat-tabs with ngFor, Initializing component twice #16397

ssahu123 opened this issue Jun 27, 2019 · 3 comments
Labels
area: material/tabs needs investigation A member of the team needs to do further investigation to determine the root cause P4 A relatively minor issue that is not relevant to core functions

Comments

@ssahu123
Copy link

ssahu123 commented Jun 27, 2019

Example -
https://stackblitz.com/edit/components-issue-otvvf6

html of main component have -
```
<mat-tab-group [(selectedIndex)]="selectedTabIndex" (selectedTabChange)="onTabSelect($event)"> <mat-tab [label]="tab.value.title" *ngFor="let tab of tabs | keyvalue"> <ng-template matTabContent> <div *ngIf="(if user tab index selected show active users)"> <active-users></active-users> </div> </ng-template> </mat-tab> </mat-tab-group>

 

#### Expected Behavior
It should initialize the user component on the selection of user tab only once.

#### Actual Behavior
But when I select user tab it initialize its component twice. 

#### Environment
- Angular: 7
- CDK/Material: 8.0.1
- Browser(s): Chrome v75
- Operating System (e.g. Windows, macOS, Ubuntu): Windows/Ubuntu
@tomicarsk6
Copy link
Contributor

Please create stackblitz for that, it’s hard to help you without an example.

@ssahu123
Copy link
Author

ssahu123 commented Jul 1, 2019

Please create stackblitz for that, it’s hard to help you without an example.

https://stackblitz.com/edit/components-issue-otvvf6

@tomicarsk6
Copy link
Contributor

tomicarsk6 commented Jul 3, 2019

You can see a solution on this stackblitz example.

Basically only difference between this and your example is that I’m using tab index value that is calculated in ngFor, instead of fixed value like you are doing.

@mmalerba mmalerba added the needs triage This issue needs to be triaged by the team label May 20, 2020
@crisbeto crisbeto added area: material/tabs needs investigation A member of the team needs to do further investigation to determine the root cause P4 A relatively minor issue that is not relevant to core functions and removed needs triage This issue needs to be triaged by the team labels May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/tabs needs investigation A member of the team needs to do further investigation to determine the root cause P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests

4 participants