我将ng-pick-datetime用于日期功能。浏览文档和示例代码后,我发现我们可以创建一个自定义页面来处理日期格式。但是文档样本代码引发了问题。我不知道是否是因为我正在使用Angular 9。

代码

// custom-date-time-adapter.class.ts
import { Injectable } from '@angular/core';
import { DateTimeAdapter } from 'ng-pick-datetime';

export const CUSTOM_DATE_TIME_FORMATS = {
    parseInput: 'your custom value',
    fullPickerInput: 'your custom value',
    datePickerInput: 'your custom value',
    timePickerInput: 'your custom value',
    monthYearLabel: 'your custom value',
    dateA11yLabel: 'your custom value',
    monthYearA11yLabel: 'your custom value',
};

@Injectable()
export class CustomDateTimeAdapter extends DateTimeAdapter<T> {
}

来自NgPickDatetime的代码。

问题
javascript - 日期格式的自定义页面-LMLPHP

最佳答案

'CustomDateTimeAdapter'不是抽象类,它需要继承'DateTimeAdapter'成员作为子类。

“DateTimeAdapter”中的成员或方法与类一样被标记为抽象。您不能直接直接实例化其成员或方法,因为它是抽象的。这是TypeScript的一部分

在代码中添加以下内容

export class CustomDateTimeAdapter extends DateTimeAdapter<any> {   //Use "any" instead of "T"
    protected locale: any;
    protected _localeChanges: import("rxjs").Subject<void>;
    localeChanges: import("rxjs").Observable<void>;
    protected millisecondsInDay: 86400000;
    protected milliseondsInMinute: 60000;
    getYear(date: any): number {
        throw new Error("Method not implemented.");
    }
    getMonth(date: any): number {
        throw new Error("Method not implemented.");
    }
    getDay(date: any): number {
        throw new Error("Method not implemented.");
    }
    getDate(date: any): number {
        throw new Error("Method not implemented.");
    }
    getHours(date: any): number {
        throw new Error("Method not implemented.");
    }
    getMinutes(date: any): number {
        throw new Error("Method not implemented.");
    }
    getSeconds(date: any): number {
        throw new Error("Method not implemented.");
    }
    getTime(date: any): number {
        throw new Error("Method not implemented.");
    }
    getNumDaysInMonth(date: any): number {
        throw new Error("Method not implemented.");
    }
    differenceInCalendarDays(dateLeft: any, dateRight: any): number {
        throw new Error("Method not implemented.");
    }
    getYearName(date: any): string {
        throw new Error("Method not implemented.");
    }
    getMonthNames(style: "long" | "short" | "narrow"): string[] {
        throw new Error("Method not implemented.");
    }
    getDayOfWeekNames(style: "long" | "short" | "narrow"): string[] {
        throw new Error("Method not implemented.");
    }
    getDateNames(): string[] {
        throw new Error("Method not implemented.");
    }
    toIso8601(date: any): string {
        throw new Error("Method not implemented.");
    }
    isEqual(dateLeft: any, dateRight: any): boolean {
        throw new Error("Method not implemented.");
    }
    isSameDay(dateLeft: any, dateRight: any): boolean {
        throw new Error("Method not implemented.");
    }
    isValid(date: any): boolean {
        throw new Error("Method not implemented.");
    }
    invalid() {
        throw new Error("Method not implemented.");
    }
    isDateInstance(obj: any): boolean {
        throw new Error("Method not implemented.");
    }
    addCalendarYears(date: any, amount: number) {
        throw new Error("Method not implemented.");
    }
    addCalendarMonths(date: any, amount: number) {
        throw new Error("Method not implemented.");
    }
    addCalendarDays(date: any, amount: number) {
        throw new Error("Method not implemented.");
    }
    setHours(date: any, amount: number) {
        throw new Error("Method not implemented.");
    }
    setMinutes(date: any, amount: number) {
        throw new Error("Method not implemented.");
    }
    setSeconds(date: any, amount: number) {
        throw new Error("Method not implemented.");
    }
    createDate(year: number, month: number, date: number);
    createDate(year: number, month: number, date: number, hours: number, minutes: number, seconds: number);
    createDate(year: any, month: any, date: any, hours?: any, minutes?: any, seconds?: any) {
        throw new Error("Method not implemented.");
    }
    clone(date: any) {
        throw new Error("Method not implemented.");
    }
    now() {
        throw new Error("Method not implemented.");
    }
    format(date: any, displayFormat: any): string {
        throw new Error("Method not implemented.");
    }
    parse(value: any, parseFormat: any) {
        throw new Error("Method not implemented.");
    }
    compare(first: any, second: any): number {
        throw new Error("Method not implemented.");
    }
    compareYear(first: any, second: any): number {
        throw new Error("Method not implemented.");
    }
    deserialize(value: any) {
        throw new Error("Method not implemented.");
    }
    setLocale(locale: any): void {
        throw new Error("Method not implemented.");
    }
    clampDate(date: any, min?: any, max?: any) {
        throw new Error("Method not implemented.");
    }
}

10-04 15:07