gpt4 book ai didi

angular - DatePicker 在 Mat Dialog 窗口中不工作

转载 作者:行者123 更新时间:2023-12-02 02:47:20 27 4
gpt4 key购买 nike

我正在尝试创建一个表单,其中包含两个使用 Angular Material 的开始/结束日期日期选择器。出于某种原因,当我在对话框窗口的表单内添加日期选择器时,从图像中可以看出,对话框的布局没有正确呈现。这可能是什么原因造成的?

模板:

<div class="consumption-form">
<form [formGroup]="consumptionControl" id="consumptionForm">
<p class="consumption-field">
<mat-form-field hintLabel="Max 10 characters" appearance="fill">
<mat-label>BGpoint</mat-label>
<input matInput #BGpoint maxlength="10" placeholder="BG5521900640000000000000001668712" formControlName="BGpointControl">
<mat-error>
<span *ngIf="consumptionControl?.controls.BGpointControl?.errors?.pattern">Field should contain 10 numeric
characters!</span>
</mat-error>
<mat-hint align="end">{{BGpoint.value?.length || 0}}/10</mat-hint>
</mat-form-field>
</p>
<p class="consumption-field">
<mat-form-field appearance="fill">
<mat-label>Choose a start date</mat-label>
<input matInput [matDatepickerFilter]="myFilter" [matDatepicker]="picker">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
</p>

<button mat-raised-button type="submit" (click)="submit(BGpoint) " mat-icon-button matTooltip="Click to search for results " [matTooltipPosition]="position.value " [matTooltipShowDelay]="500
" [matTooltipHideDelay]="500">
<mat-icon aria-label="Search button icon ">search</mat-icon>
</button>

</form>
</div>

组件 ts:

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { TooltipPosition } from '@angular/material/tooltip';

@Component({
selector: 'app-consumption-details',
templateUrl: './consumption-details.component.html',
styleUrls: ['./consumption-details.component.css']
})
export class ConsumptionDetailsComponent implements OnInit {

myFilter = (d: Date | null): boolean => {
const day = (d || new Date()).getDay();
// Prevent Saturday and Sunday from being selected.
return day !== 0 && day !== 6;
}

consumptionControl: FormGroup;
private positionOptions: TooltipPosition[] = ['after', 'before', 'above', 'below', 'left', 'right'];
position = new FormControl(this.positionOptions[0]);
constructor() { }

ngOnInit(): void {
this.consumptionControl = new FormGroup({
BGpointControl: new FormControl('', [Validators.minLength(1), Validators.maxLength(20), Validators.pattern("*")]),
});
}
submit(BGPoint:string){

}

}

对话窗口显示为屏幕左侧从上到下的白色 strip 。

最佳答案

我知道我参加聚会有点晚了,但我遇到了与 OP 类似的问题。在我的例子中,mat-datepicker 工作正常,直到我试图将它放在 mat-dialog 窗口中的表单中。即使在我的模块中导入了 MatNativeDateModuleMatDatepickerModule,我仍然在控制台中收到 ERROR Error: MatDatepicker: No provider found for DateAdapter

对我有用的是在 MyModuleAppModule 中导入上面的模块 and 同时注册 MatDatepickerModule 作为 MyModule 中的提供者。

关于angular - DatePicker 在 Mat Dialog 窗口中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62592867/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com