Topic: MDBDatePickerComponent set default date
metalor-it pro asked 6 years ago
Failed to set initial date on date picker, even using code with MDBDatePickerComponent ViewChild. Why there are no simple function to set the date?? If the date set is of type "Date" nothing is displayed, and date selection failed to parse. So I tried with a type "any" and set a string instead of a date. First display is ok, well formatted, but if I select a new date, the displayed format is lost.!? I even tried using moment..
HTML: [(ngModel)]="selectedDate"
Typescript: public selectedDate: any; public datePickerOptions: IMyOptions; ngOnInit: this.datePickerOptions.dateFormat = 'dd.mm.yyyy';
I simply want to set an initial date, and read it as 2 way binding. Of course with formatted date displayed. This is a total nightmare .
Arkadiusz Idzikowski staff answered 6 years ago
Here is an example for ngModel binding:
selectedDate: any = { date: { year: 2019, month: 4, day: 20 } };
You can also pass a string to the 'selDate' input:
[selDate]="'2019-04-20'"
metalor-it pro commented 6 years ago
But TypeScript has a type Date.. Does that means I have to turn it into json each time, and parse it back while getting the value ? I didn't try selDate with double + simple quote.. This datepicker is a real pain (no offense). The documentation miss the default binding sample. Thanks
Arkadiusz Idzikowski staff commented 6 years ago
Unfortunately, it's not possible to set default date with js date object, but date in this format is emitted in (dateChanged) event after selection.
We will add more examples to the documentation.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- User: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: 7.3.0
- Device: PC
- Browser: Chrome
- OS: Windows
- Provided sample code: No
- Provided link: No