title: SelectedIndex mat-tab doesn’t work in ngif
body: <p>Good day, I need initialize my mat-tab in the first tab, but I can´t when I use *ngIf.</p>
  <p>This is my code :</p>
  <p>html</p>
  <pre><code>&lt;mat-tab-group dynamicHeight&gt; 
  
    &lt;mat-tab label=&quot;RENT&quot; *ngIf=&quot;showRent&quot;&gt; 
    
      &lt;div class=&quot;rc-result&quot; &gt; 
    
        &lt;mat-card class=&quot;rc-available&quot;&gt; 
    
          {{rent}} 
    
        &lt;/mat-card&gt; 
    
      &lt;/div&gt; 
    
    &lt;/mat-tab&gt; 
    
    &lt;mat-tab label=&quot;FILTERS&quot;&gt; 
    
      &lt;div class=&quot;rc-result&quot; &gt; 
      
          &lt;mat-card class=&quot;rc-available&quot;&gt; 
      
            {{filters}} 
      
          &lt;/mat-card&gt; 
      
      &lt;/div&gt; 
    
    &lt;/mat-tab&gt; 
    
  &lt;/mat-tab-group&gt; 
  </code></pre>
  <p>component.ts</p>
  <pre><code>import { Component, OnInit, ViewChild } from '@angular/core'; 
      
  import { MatTabGroup} from '@angular/material/tabs'; 
      
  </code></pre>
  <p>my variables</p>
  <pre><code>  @ViewChild(MatTabGroup) tabGroup!: MatTabGroup; 
    showRent: Boolean = false; 
  </code></pre>
  <p>in the ngOnInit. Depend on the origin of data the tab initialize in cero or one.</p>
  <pre><code>        this._bridge.sentParams 
                       .subscribe((payload: any) =&gt; { 
                          this.myPayloadForm = payload. Data;  
                          if (this.myPayloadForm.home === 'ahri'){ 
                            this.showRent = false;                                                
                            this.tabGroup.selectedIndex = 1; 
                          } else { 
                            this.showRent = true;                                                          
                            this.tabGroup.selectedIndex = 0; 
                          }           
               }); 
         } 
      
  </code></pre>
  <p>I appreciate your support and interest in helping me</p>