11

date input is not showing the date until the user change it

// showing the date
<p>{{someDate | date}}</p>

// not showing the date. instead showing mm/dd/yyyy.  
// but value will change when use change is
<input type="date" ng-model="someDate">

example code in jsbin

it IS working on version 1.3.0-beta.3, but

I need it to work on stable version 1.2.14. is it possible?

2
  • it works if you use <input type='text'>. Can you use bootstraps datepicker instead of the native html5 type='date'? Commented Mar 26, 2014 at 16:36
  • It is not working for me on AngularJS 1.3.0-rc.1 Commented Sep 18, 2014 at 13:32

3 Answers 3

8

I've created a simple directive to enable standard input[type="date"] form elements to work correctly with AngularJS ~1.2.16.

Please look here for details: https://github.com/betsol/angular-input-date

And here's the demo: http://jsfiddle.net/F2LcY/2/

Hope it helps!

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

5 Comments

why is the directive adding a month to the initialized date?
@PilotBob well, it shouldn't. Please create an issue and attach a Plunk to demonstrate the problem. I will try to fix it as soon as possible. Thanks )
Here is what I see when I view the jsfiddle linked above. You initialize the date to March 19th but I see April 19. screencast.com/t/WJmhhSx65
@PilotBob I think you are confused with the Date object API. When you instantiate a new Date object in the JavaScript the month value is zero-based, not one-based. So the 3 is actually an April (3 + 1 = 4). Please see the docs: developer.mozilla.org/en/docs/Web/JavaScript/Reference/… Don't ask me why JavaScript creators decided to do such a weird thing ))
Ah, I was wondering if that was the issue, but then thought, no, that would be a most stupid API.
2

I think the answer is you must upgrade to angularjs 1.3 or newer. Details in angular.js/pull/5864. The commit implementing this is pretty large to try to backport to 1.2 IMHO.

Comments

0

Try converting the someDate scope variable from string to Date format and then if you use input type="date" ng-model="someDate" . This solved my problem .

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.