angular-datepicker
angular-datepicker copied to clipboard
date-picker returns empty string if min-date is defined (which does not work either)
My variables definded in Controller:
this.scheduleDate = {};
this.today = new Date();
My template:
<div
date-picker
ng-model = "$ctrl.scheduleDate"
min-date = "$ctrl.today"
view = "date"
min-view = "date"
max-view = "date"
></div>
And when I select a day from date-picker, I got " " in return. I'm using Angular 1.5. Date-picker is inside component, if it matters.
I found this out today. The only thing you can put into min-date and max-date is the name of a variable that exists in $scope. Apparently this control does not support angular expressions...
OK, I am putting the variable name, which gets interpreted correctly on screen, but, for some reason, min-date doesn't work (the field doesn't got invalid). Debugging the code, here's what I found out: Inside the angular-datepicker.js file, this funcion:
function setMin(date) { minDate = date; attrs.minDate = date ? date.format() : date; minValid = moment.isMoment(date); }
Is receiving 'false' as the date value. On my html, I'm passing min-date as:
<input type="datetime" name="date" class="form-control" data-container="body" date-time ng-model="newUser.date" view="date" auto-close="true" min-date = "{{todayDate}}" required min-view="date" format="DD-MM-YYYY">
And, in my controller, I define todayDate as:
$scope.todayDate = new Date();
I also tried filtering the variable in html as:
min-date = "{{todayDate | date:'yyyy-MM-dd' }}"
But it gives me the same result.
My memory on that matter isn't exactly fresh, but from what I've written above you would need to write <input ... min-date = "todayDate" ...>
without the curly braces.
I have no idea why I hadn't tried that before, but it worked! Thanks @davidda !! It only worked using moment.js (in case anyone bumps into this in the future).