簡體   English   中英

選擇單選按鈕時如何隱藏日期選擇器?

[英]How to hide datepicker when radio button is selected?

所以,我有日期選擇器和一個單選按鈕。 我想在選擇單選按鈕時隱藏日期選擇器。

所以這是日期選擇器:

     <div formGroupName="groupDateTwo">
            <mat-form-field class="search-field-input md-datepicker-input-container">
              <input
                matInput
                readonly
                required
                [matDatepicker]="picker2"
                placeholder="start datum"
                formControlName="startDate"
                (ngModelChange)="onChange($event)"
              />
              <mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
              <mat-datepicker #picker2></mat-datepicker>
            </mat-form-field>
          </div>

這是選擇單選按鈕時:


if (optionLabel === 'Registratie') {   


    }

這是日期字段:

startDate: Date;

所以我的問題是,當在 ts 腳本中選擇單選按鈕時,你能隱藏日期選擇器嗎?

謝謝

只需在組件或 class 的構造函數上方添加一個新的數據綁定屬性

showDatePicker: boolean = true;

在您的單選按鈕選擇掛鈎中,將true分配給上述數據綁定屬性。

if (optionLabel === 'Registratie') {   
   this.showDatePicker = false;
}

最后在您的組件 html 中,使用*ngIf="expression"[hidden]="expression"

<mat-form-field class="search-field-input md-datepicker-input-container" *ngIf="showDatePicker">
  ...
</mat-form-field>
<ng-template [ngIf]="optionLabel=='Registratie'">
 <mat-form-field class="search-field-input md-datepicker-input-container">
          <input
            matInput
            readonly
            required
            [matDatepicker]="picker2"
            placeholder="start datum"
            formControlName="startDate"
            (ngModelChange)="onChange($event)"
          />
      <mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
    <mat-datepicker #picker2></mat-datepicker>
  </mat-form-field>
</ng-template>

這意味着如果 optionLabel=='Registratie' 那么它將顯示日期選擇器

暫無
暫無

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

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