Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extending NativeDateTimeAdapter: error NG2003: No suitable injection token for parameter 'owlDateTimeLocale' of class 'CustomDateTimeAdapter' #166

Open
NishaJKulal opened this issue Aug 25, 2022 · 0 comments

Comments

@NishaJKulal
Copy link

Could you please provide details on what is the right approach to use custom Date time picker?

The one mentioned below does not work
https://danielykpan.github.io/date-time-picker/#locale-formats

We have tried implementing referring to the code snippet in - #130 (comment)

We need to inject a service in the CustomDateTimePicker class. Since we extend NativeDateTimeAdapter class it throws error while we inject owlDateTimeLocale which is a private string variable.

custom-date-time-format.ts

@Injectable({providedIn: 'root'})
export class CustomDateTimeAdapter extends NativeDateTimeAdapter {
constructor(
owlDateTimeLocale: string,
platform: Platform,
private readonly languageDetail: LanguageDetailService
) {
super(owlDateTimeLocale, platform)
}

format(date: Date, format): string {
if (!this.isValid(date)) {
throw Error('JSNativeDate: Cannot format invalid date.');
}
return ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear();
}

Angular version used: 14.1.0

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant