Closed zhenokin closed 3 years ago
i think you can't do that. (import it like that) i think NativeDateTimeModule is exported but not the NativeDateTimeAdapter (in public api) so i don't think you can extend it
not sure why it is not exported here https://github.com/danielmoncada/date-time-picker/blob/master/projects/picker/src/public_api.ts
@jcompagner I used https://github.com/DanielYKPan/date-time-picker on angular 6 and my case worked fine. But I'm trying to migrate to the latest angular version and I am faced with this problem.
Can anyone know how this can be implemented in another way?
import { DateTimeAdapter, OWL_DATE_TIME_LOCALE } from 'ng-pick-datetime';
import { NativeDateTimeAdapter } from 'ng-pick-datetime/date-time/adapter/native-date-time-adapter.class';
@Injectable()
export class CustomTimeAdapter extends NativeDateTimeAdapter {
format(date: Date, displayFormat: any): string {
if (!this.isValid(date)) {
throw Error('JSNativeDate: Cannot format invalid date.');
}
date = new Date(Date.UTC(
date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(),
date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
return ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear();
}
}
@NgModule({
declarations: [
...
],
imports: [
...
],
providers: [
...
{ provide: DateTimeAdapter, useClass: CustomTimeAdapter, deps: [OWL_DATE_TIME_LOCALE, Platform] },
],
})
i don't think you really can its not public api. I think the component should also export NativeDateTimeAdapter to be able to do this
This is implemented in version 12.2.0
package.json
app.module.ts
Created new app via ng new projectName. After ng serve command I get this error:
./src/app/app.module.ts:4:0-132 - Error: Module not found: Error: Can't resolve '@danielmoncada/angular-datetime-picker/lib/date-time/adapter/native-date-time-adapter.class' in 'C:\...\Desktop\test\angular\src\app'