簡體   English   中英

角度-移除mat-tab中的標簽

[英]Angular - Remove label in mat-tab

我有一個包含兩個標簽的表格。
基於* ngIf,我決定要顯示哪種標簽。
-如果我的表單是視圖,則我想查看兩個帶有標簽的選項卡(兩個選項卡都有向用戶顯示的信息,第二個選項卡是結果)。
-如果我的表單是一個添加項,那么我不想看到任何標簽,因此也看不到任何標簽。

我不願意創建兩個單獨的文件,因為我試圖盡可能減少代碼。

我嘗試添加一個ng-template來替換mat-tab-label,但是我沒有刪除它,而是將其刪除。

空標簽的示例

到目前為止,這就是我所擁有的。 我的問題是:是否可以在不創建新文件的情況下刪除整個標簽標簽,如果可以,我該怎么辦?

<mat-dialog-content class="ManageTask">
<form [formGroup]="form">
    <mat-tab-group mat-stretch-tabs>
        <mat-tab>
            <ng-template *ngIf="isView()" mat-tab-label>Task details</ng-template>
            <div class="left">
                <mat-form-field class="full-width">
                    <input matInput type="text" placeholder="Name" formControlName="name">
                    <mat-error *ngIf="form.controls['name'].hasError('required')">Name required</mat-error>
                </mat-form-field>
                <br/>
                <mat-form-field class="full-width">
                    <textarea matInput type="text" placeholder="Description" formControlName="description"></textarea>
                    <mat-error *ngIf="form.controls['description'].hasError('required')">Description required</mat-error>
                </mat-form-field>
            </div>
        </mat-tab>
        <mat-tab *ngIf="isView()" label="Task results">
            <div>...MORE CONTENT...</div>
        </mat-tab>
    </mat-tab-group>
</form>

我不確定我是否理解這個問題。一定可以做到。使用<ng-template>ngIf正確方法是這樣的:

<ng-template [ngIf]="isView()">
    <mat-tab label="Task details">...</mat-tab>
</ng-template>

要么 :

<mat-tab *ngIf="isView()" label="Task details">...</mat-tab>

[ngif]*ngif之間的*ngif角度結構指令

希望對您有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM