AngularMaterial日期选择器忽略了输入的格式。
创始人
2024-10-28 10:01:17
0

在HTML模板中添加一个input元素,通过[(ngModel)]指令将选择的日期值绑定到一个日期对象属性。


  
  
  

在组件类中声明选定日期对象的属性,并使用指令@ViewChild来获取MatDatePicker对象。然后,可以在日期选择器的日期更改事件中更新另一个属性,以便在进行提交前在所需的格式中提供字符串表示形式。

import { Component, ViewChild } from '@angular/core';
import { MatDatepicker } from '@angular/material/datepicker';

@Component({
  selector: 'datepicker',
  templateUrl: './datepicker.component.html',
  styleUrls: ['./datepicker.component.css']
})
export class DatepickerComponent {
  @ViewChild(MatDatepicker) picker: MatDatepicker;
  selectedDate: Date;
  formattedDate: string;

  onDateChange(event): void {
    this.formattedDate = this.selectedDate.toISOString().slice(0, 10);
  }
}

最后,使用相应的格式将选择的日期值提交到服务器。

onSubmit(): void {
  const data = { date: this.formattedDate };
  this.http.post('/api/date', data).subscribe(response => console.log(response));
}

相关内容

热门资讯

做出回应!德扑之心免费透视,顺... 做出回应!德扑之心免费透视,顺欣茶楼怎么开挂,其实真的是有辅助神器(哔哩哔哩)1、很好的工具软件,可...
经调查!wepoker免费脚本... 经调查!wepoker免费脚本,潮友会虾蟹骰子概率计算方式,一贯是真的有辅助插件(哔哩哔哩)1、让任...
目前!hhpoker有没有作必... 目前!hhpoker有没有作必弊挂,哈糖大菠萝助手,本来有辅助app(哔哩哔哩)1、游戏颠覆性的策略...
受玩家影响!we-poker辅... 受玩家影响!we-poker辅助软件教程,微信微乐开挂,其实存在有辅助工具(哔哩哔哩)1、全新机制【...
为切实保障!hhpoker外开... 为切实保障!hhpoker外开挂靠谱吗,多乐辅助器使用方法,真是是真的有辅助工具(哔哩哔哩)1、多乐...
近年来!wepoker好友助力... 近年来!wepoker好友助力码,闲逸辅助器,原来存在有辅助app(哔哩哔哩)闲逸辅助器是不是有人用...
此事备受玩家关注!wepoke... 此事备受玩家关注!wepoker模拟器哪个,兴动互娱辅助设置步骤详解,果然是真的有辅助技巧(哔哩哔哩...
随着!cloudpoker作必... 您好,土豪联盟辅助软件下载这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很...
此事引发网友热议!pokemm... 此事引发网友热议!pokemmo脚本辅助器下载,雀神麻将辅助透视,都是真的有辅助软件(哔哩哔哩)1)...
日前!hhpoker有没有作必... 日前!hhpoker有没有作必弊辅助,天天爱游戏辅助,原来真的有辅助方法(哔哩哔哩)1、游戏颠覆性的...