我想根据用户类型动态设置'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',
},
};
我在Cookie中设置此值并从cookie中获取数据以处理此问题。