AngularMaterial日期选择器默认日期不正确
创始人
2024-10-28 10:01:20
0

可以通过在组件中设置默认日期来解决此问题。在组件的构造函数中使用Angular DatePipe来格式化日期字符串,并将其传递给FormControl。例如:

import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { DatePipe } from '@angular/common';

@Component({
  selector: 'app-date-picker',
  templateUrl: './date-picker.component.html',
  styleUrls: ['./date-picker.component.scss']
})
export class DatePickerComponent implements OnInit {
  date = new FormControl('');
  
  constructor(private datePipe: DatePipe) {
    this.date.setValue(this.datePipe.transform(new Date(), 'yyyy-MM-dd'));
  }

  ngOnInit(): void {
  }

}

这将在组件加载时将当前日期作为默认日期设置为FormControl值。您还可以使用其他格式化字符串来更改日期的显示方式。此方法适用于Angular 11及更高版本。

相关内容

热门资讯

透视智能ai!pokerrrr... 透视智能ai!pokerrrr2辅助,epoker透视底牌(一贯存在有挂);1、让任何用户在无需ep...
aapoker辅助工具!aap... 1、aapoker辅助工具!aapoker德州线上扑克辅助工具,(aaPoker)确实是有挂,详细教...
透视脚本!德州透视是真的吗,p... 透视脚本!德州透视是真的吗,pokemmo辅助脚本(总是真的有挂)1、点击下载安装,德州透视是真的吗...
aapoker俱乐部!aapo... aapoker俱乐部!aapoker有手游版吗,(Aapoker)总是是真的有挂,详细教程(有挂辅助...
透视好友!智星菠萝透视,pok... 透视好友!智星菠萝透视,pokemmo修改器手机版(确实真的有挂)pokemmo修改器手机版辅助器中...
aapoker透视辅助!aap... aapoker透视辅助!aapoker辅助工具下载,(AAPOKER)总是有挂,详细教程(有挂详情)...
透视透视!xpoker辅助助手... 透视透视!xpoker辅助助手,pokemmo辅助器手机版下载(原来是有挂);在进入pokemmo辅...
aapoker透明挂!aapo... aapoker透明挂!aapoker发牌规律,(AAPoker)总是是真的有挂,详细教程(有挂教程)...
透视规律!拱趴大菠萝万能挂图解... 透视规律!拱趴大菠萝万能挂图解,大菠萝免费辅助(本来有挂)拱趴大菠萝万能挂图解软件透明挂微扑克wpk...
aapoker有猫腻!aapo... aapoker有猫腻!aapoker有什么规律吗,(AAPOker)真是是真的有挂,详细教程(有挂辅...