0

I have simple date object made in JS and I don't know why AngularJS can't bind it to the input control(Probably the problem is the format of date) but please explain me it. The sample problem occurs when I return Json object which contains date.

View:

<div ng-controller="MyCtrl" ng-app>
    <input type="date" ng-model="dateVal" />
        <hr/>   
    {{dateVal}}  </br>    
</div>

Controller:

function MyCtrl($scope) {
    $scope.dateVal = new Date(2013, 06,07);   
}

Entire example is placed here - jsfiddle

1 Answer 1

4

The input control doesn't appear to bind to a date object, but a string object.

Change your dateVal to a string like

$scope.dateVal = "2013-06-07";

See this fiddle http://jsfiddle.net/2BZV4/2/

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

2 Comments

I was just about to post this very answer. Here's the spec for the date input type. Something to keep in mind (although I'm sure the OP is aware) - not all browsers support that input type (Firefox doesn't, for example.)
I didn't check specyfication for date input I thought it's something with format and angularjs. Eh. Thanks a lot for help.

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.