![](/img/trans.png)
[英]Mat-tab material angular6 selectedIndex doesn't work with *ngFor
[英]SelectedIndex mat-tab doesn’t work in ngif
美好的一天,我需要在第一個選項卡中初始化我的 mat-tab,但是當我使用 *ngIf 時我不能。
這是我的代碼:
html
<mat-tab-group dynamicHeight>
<mat-tab label="RENT" *ngIf="showRent">
<div class="rc-result" >
<mat-card class="rc-available">
{{rent}}
</mat-card>
</div>
</mat-tab>
<mat-tab label="FILTERS">
<div class="rc-result" >
<mat-card class="rc-available">
{{filters}}
</mat-card>
</div>
</mat-tab>
</mat-tab-group>
組件.ts
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatTabGroup} from '@angular/material/tabs';
我的變量
@ViewChild(MatTabGroup) tabGroup!: MatTabGroup;
showRent: Boolean = false;
在 ngOnInit 中。 取決於數據的來源,選項卡在 cero 或 one 中初始化。
this._bridge.sentParams
.subscribe((payload: any) => {
this.myPayloadForm = payload. Data;
if (this.myPayloadForm.home === 'ahri'){
this.showRent = false;
this.tabGroup.selectedIndex = 1;
} else {
this.showRent = true;
this.tabGroup.selectedIndex = 0;
}
});
}
感謝您的支持和有興趣幫助我
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.