Search code examples
angularjsangularjs-model

Angular JS get value of date input with ng-model


I try to get the value of my input date html 5 component by binding it with ng-model like this:

<input type="date" id="dateFin" class="form-control" name="dateFin" ng-model="filtres.dateFin"
               placeholder="dd/MM/yyyy" min="01/01/2014"/>

And with the model :

$scope.filtres.dateFin = null;

I think the binding is correct because when I change the initial value to

$scope.filtres.dateFin = new Date(); 

The initial value is set to current date.

But my problem occurs when i try to get the value on my form processing. When debugging I saw that the value of $scope.filtres.dateFin become undefined when the value is changed. Should I override an onchange method or getting the value by another way?


Solution

  • Ok, so, a little thanks your example I managed to find the issue. In fact I had a min-value and a format like placeholder="dd/MM/yyyy" min="01/01/2014" and this was preventing my code which was similar to yours to work.

    I think the problem was the format of the min parameter with the good format everything is ok :

     min="2014-01-01"
    

    My bad for removing for my code example on the question, I was juste trying to make it more readable.