angular-ui / bootstrap

PLEASE READ THE PROJECT STATUS BELOW. Native AngularJS (Angular) directives for Bootstrap. Smaller footprint (20kB gzipped), no 3rd party JS dependencies (jQuery, bootstrap JS) required. Please read the README.md file before submitting an issue!
http://angular-ui.github.io/bootstrap/
MIT License
14.28k stars 6.73k forks source link

Datepicker not opening on pre-populated date #6556

Closed DeanWilliamMills closed 7 years ago

DeanWilliamMills commented 7 years ago

If the ng-model has a value (populated from the database) and you open the datepicker it opens on today's date and not on the ng-model date. When you close the datepicker and open it again then it opens on the pre-populated date. So it only happens the first time you open the datepicker

WVWillHall commented 7 years ago

Sounds like a race condition to me.

You try adding an ng-init and explicitly setting the model yet?

DeanWilliamMills commented 7 years ago

@WVWillHall Thanks for the reply. I also tried adding ng-init, but still doesn't work.

Here is my code snippet:

Controller: $scope.testDate = new Date($scope.date.getFullYear() - 10, $scope.date.getMonth(), 1);

HTML: <input ng-model="testDate" type="text" readonly class="form-control" uib-datepicker-popup="{{datepickerOptions.format}}" is-open="datepickerToggle" />

image

WVWillHall commented 7 years ago

working for me.

https://plnkr.co/edit/e5zD5MlP7GvVFCRASjNv?p=preview

DeanWilliamMills commented 7 years ago

@WVWillHall thanks for your help. I realized I was not on the latest version. After updating to the latest version the issue was resolved.