I'm currently developing a project using Ionic framework and I need to set a default date (which is today's date) on an input field.
My code works perfectly when the input type is set to text, but it doesn't work if I specify the type as date.
This is the HTML code snippet:
<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Date with Ionic</title>
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
</head>
<body ng-controller="GraphCtrl">
<ion-header-bar class="bar-positive">
<h1 class="title">Ionic Date</h1>
</ion-header-bar>
<ion-content>
Text : <input type="text" ng-model="date_rdv" />
Date : <input type="date" ng-model="date_rdv" />
</ion-content>
</body>
</html>
Here is my JavaScript code:
angular.module('ionicApp', ['ionic'])
.controller('GraphCtrl', function($scope, $filter) {
$scope.date_rdv = $filter('date')(Date.now(), 'yyyy-MM-dd');
});
Any suggestions or solutions?
Resolution (based on Elec's response)
To set a default value on a date input field (which does not work on text input), you should define your model like this:
$scope.date_rdv = new Date();