[英]angularJS how to dynamically bind input type date max/min value
How to dynamically bind input field of date type with maximum date value in AngularJS? 如何在AngularJS中将日期类型的输入字段与最大日期值动态绑定? There are no
ng-max
, ng-min
directives provided by AngularJS. AngularJS没有提供
ng-max
, ng-min
指令。
Check out this fiddle . 看看这个小提琴 。 Just bind your
$scope
vars directly into the tag attributes. 只需将
$scope
变量直接绑定到标签属性中即可。 I used moment.js for date handling. 我使用moment.js进行日期处理。
<div ng-controller="MyCtrl">
<input type="date" min="{{ min }}" max="{{ max }}" />
</div>
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function ($scope) {
//init dates
var minDate = new moment();
var maxDate = new moment().add(18, 'years');
$scope.min = minDate.format("YYYY-MM-DD");
$scope.max = maxDate.format("YYYY-MM-DD");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.