如何在Angular中设置角度日期选择器日期格式作为服务方法?

问题描述 投票:0回答:1

我想根据用户类型动态设置'dateInput'表示Auth服务。我使用'ServiceName.getMethod',我试图通过创建一个类来解决它,但它没有解决。

 export class SchoolDateFormat {
    public schoolDateFormat = '';
    constructor(private auth: AuthenticationService) {
        if ( this.auth.isLoggedIn() ) {
            if ( this.auth.isSystemUser() ) {
                this.schoolDateFormat = this.auth.getCountryDateFormat();
            }else {
                this.schoolDateFormat = 'YYYY-MM-DD';
            }
        }else {
            this.schoolDateFormat = 'YYYY-MM-DD';
        }
    }
    get getDateFormat() {
        return this.schoolDateFormat;
    }
}

const schoolDate = new SchoolDateFormat([AuthenticationService]);

export const MY_FORMATS = {
        parse: {
            dateInput: 'YYYY-MM-D',
        },
        display: {
            dateInput: schoolDate.getDateFormat,
            monthYearLabel: 'MMM YYYY',
            dateA11yLabel: 'LL',
            monthYearA11yLabel: 'MMMM YYYY',
        },
    };
angular typescript angular-services
1个回答
0
投票

我在Cookie中设置此值并从cookie中获取数据以处理此问题。

© www.soinside.com 2019 - 2024. All rights reserved.