1

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?

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.