I'm trying to show a date object in my view.
I followed these docs: https://docs.angularjs.org/api/ng/input/input%5Bdate%5D
But without success.
I literally have the same code: (EDIT: Removed controllerAs syntax and added $scope)
<input type="date" name="birthDate" ng-model="example.value"
placeholder="yyyy-MM-dd" min="2013-01-01" max="2013-12-31" required />
and my object:
$scope.example = {
value: new Date(2013, 9, 22)
};
But still I get an error
Error: [ngModel:datefmt] Expected
2013-10-22
to be a date
Does anyone know what is causing this problem? I tried looking online but all the answers I found were saying the Date Object is invalid, which I'm pretty sure mine isn't. (or is it??)
EDIT:
Since a lot of people are having trouble understanding what my problem is, let me illustrate with a jsfiddle: http://jsfiddle.net/j2kof5at/
In the output I see 'dd-mm-2013' instead of '22-10-2014'. Why is this?
EDIT 2: (SOLUTION)
One of the solutions I tried was by adding angular-input-date module to my project. I just removed this from my project and it seems as if the problem is resolved. Reading the docs for this module I found:
The latest stable version of AngularJS (~1.2.26) has no support for input[type="date"]. The support was added only for 1.3 branch of Angular, which is now in beta.
Since I'm using angular 1.5.x there is already native support for this and this module was actually causing the problem. This also explains why my jsfddle isn't working, since that is using angular 1.0.1