Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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?

share|improve this question

https://jsfiddle.net/u2vkzemh/

html

<div ng-app ng-controller="testCtrl">
    <input type="date" id="dateFin" name="dateFin" ng-model="filtres.dateFin"/>
    {{filtres.dateFin}}
    <button type="button" ng-click="show()">Show it</button>
    {{testDate}}
</div>

controller

function testCtrl($scope) {
    $scope.show=function(){
        $scope.testDate = $scope.filtres.dateFin;
    }
}

It seems to work well.

share|improve this answer
up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.