mat-datepicker添加touchUI条件

时间:2018-07-18 05:54:38

标签: angular ionic-framework angular-material

我有一个离子应用程序,其中使用了Angular的mat-datepicker。我想让网络版本获得正常的日期选择器,并希望在移动设备上获得touchUi版本。我尝试将* ngIf用作mat-date-picker选择器,但我开始得到'Cannot read property open of undefined'

       <mat-form-field class="day-datepicker">
           <input [(ngModel)]="FilterOptions.CreatedTo" disabled matInput [matDatepicker]="picker4">

            <mat-datepicker #picker4 *ngIf="_AppConfig.IsCordova" touchUi="true" disabled="false">
            </mat-datepicker>

            <mat-datepicker #picker4 *ngIf="!_AppConfig.IsCordova" disabled="false">
            </mat-datepicker>

        </mat-form-field>

1 个答案:

答案 0 :(得分:3)

您需要像下面那样更改代码。

<mat-form-field class="day-datepicker">
    <input [(ngModel)]="FilterOptions.CreatedTo" disabled matInput [matDatepicker]="picker4">
    <mat-datepicker-toggle matSuffix [for]="picker4"></mat-datepicker-toggle>
    <mat-datepicker #picker4 [touchUi]="_AppConfig.IsCordova" disabled="false"></mat-datepicker>
</mat-form-field>`