admin管理员组文章数量:1334148
I try to set the default value of an input field at today. I can do that with an text field but when I try with an date field it fails.
HTML code :
<div ng-controller="MyCtrl">
<form name="new">
<input type="date" ng-model="date_rdv" />
<input type="text" ng-model="form_text" />
</form>
</div>
JS code :
var myApp = angular.module('myApp',[]);
function MyCtrl($scope, $filter) {
$scope.form_text = $filter('date')(Date.now(), 'yyyy-MM-dd');
$scope.date_Rdv = $filter('date')(Date.now(), 'yyyy-MM-dd');
}
Why it works with text field and not with date field ?
JSFiddle.
I try to set the default value of an input field at today. I can do that with an text field but when I try with an date field it fails.
HTML code :
<div ng-controller="MyCtrl">
<form name="new">
<input type="date" ng-model="date_rdv" />
<input type="text" ng-model="form_text" />
</form>
</div>
JS code :
var myApp = angular.module('myApp',[]);
function MyCtrl($scope, $filter) {
$scope.form_text = $filter('date')(Date.now(), 'yyyy-MM-dd');
$scope.date_Rdv = $filter('date')(Date.now(), 'yyyy-MM-dd');
}
Why it works with text field and not with date field ?
JSFiddle.
Share Improve this question asked Dec 5, 2015 at 0:21 Samuel DauzonSamuel Dauzon 11.3k15 gold badges66 silver badges100 bronze badges1 Answer
Reset to default 5You are not referencing the correct property of $scope.
Either use:
$scope.date_rdv = $filter('date')(Date.now(), 'yyyy-MM-dd');
Or
<input type="date" ng-model="date_rdv" />
.
I've updated your fiddle here:
http://jsfiddle/68j7y439/1/
本文标签: javascriptangularjs set default date input at todayStack Overflow
版权声明:本文标题:javascript - angularjs set default date input at today - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742363956a2460906.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论