How to change Angular Material Datepicker format in run-time

前端 未结 3 1853
醉话见心
醉话见心 2021-02-01 10:08

I\'m working on an Angular App with Material Design, and I\'m using Moment.js to parse and format dates.

In one of my p

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 10:42

    update: @Gil Epshtain's solution doesn't work if the user wants to manually input DateTime instead of pick DateTime from DateTime picker (remove read-only attribute on input DateTime). my update on customDateAdapter.ts:

    public parse(value: any, parseFormat: string | string[]): moment.Moment | null {
    if(!value) {
      return null
    }
    const format = this._dateTimeService.getFormat();
    return _moment(value, format, false);
    }
    

提交回复
热议问题