ngx-daterangepicker-material icon indicating copy to clipboard operation
ngx-daterangepicker-material copied to clipboard

Single date picker initial value or change it in the component

Open quedicesebas opened this issue 6 years ago • 6 comments

When using the singleDatePicker option, I can't set the initial value or chage the selected value programatically:

Template: <input type="text" name="my-date" required readonly ngxDaterangepickerMd [(ngModel)]="myDate" [singleDatePicker]="true" [autoApply]="true" />

Component: public myDate: Moment;

this.myDate= moment().add(-1, 'months');

As result, always is shown the selected date as the current date and no a month ago as should be.

My workaround was use the model like in the range selection:

public myDate: { startDate: Moment, endDate: Moment }

this.myDate= { startDate: moment().add(-1, 'months'), endDate: moment().add(-1, 'months') }

quedicesebas avatar May 06 '19 17:05 quedicesebas

Hello. I have this problem too and I try to find solutions.

bear-wolf avatar May 07 '19 08:05 bear-wolf

hello @bear-wolf @sebrojas14 , this is abug I need to solve because for single datepicker it should be directly the date. For now, until I got it solved, the workaround is to initialize with an object like the range did it: this.myDate= { startDate: moment().add(-1, 'months'), endDate: moment().add(-1, 'months') }

@sebrojas14 thank you for reporting

fetrarij avatar May 07 '19 08:05 fetrarij

I have this problem as well. I solved it using @fetrarij May 7 solution above.

Also note that if you do not manually set the start date, not only does it default to 'now', it also defaults to returning local time zone offset when selected. Manually setting start time using a UTC time seems to fix this.

rendermouse avatar Dec 18 '19 20:12 rendermouse

Hello! if i use this.myDate= { startDate: moment() } it works too

FedericoEcheverria avatar Mar 09 '21 15:03 FedericoEcheverria

Hello. @fetrarij I have this problem in single Date not set. angular version:- 12.2.0 version:- "ngx-daterangepicker-material": "^5.0.1"

ketanpanther avatar Oct 03 '22 09:10 ketanpanther

how can i get a space between From date and To date , Please repond

Shyamjith05 avatar Dec 13 '22 16:12 Shyamjith05