Angularjs 如何限制用户仅在angular bootstrap datepicker中输入日期字段

Angularjs 如何限制用户仅在angular bootstrap datepicker中输入日期字段,angularjs,html,angular-ui,Angularjs,Html,Angular Ui,我是angular方面的新手,无法限制用户手动输入有效日期。它将用户输入的空字符和无效日期设置为未定义日期。我提到的日期格式是MM dd yyyy。即使我输入85/34/2102,它也会假定这是一个日期,并接受一些垃圾值,而不是验证和抛出错误 我的html角度日期选择器代码 <input type="text" class="form-control" datepicker-popup="{{clCtrl.format}}" ng-model="clCtrl.QualityExp

我是angular方面的新手,无法限制用户手动输入有效日期。它将用户输入的空字符和无效日期设置为未定义日期。我提到的日期格式是MM dd yyyy。即使我输入85/34/2102,它也会假定这是一个日期,并接受一些垃圾值,而不是验证和抛出错误

我的html角度日期选择器代码

 <input type="text" class="form-control" datepicker-popup="{{clCtrl.format}}" 
   ng-model="clCtrl.QualityExpirationDate" is-open="clCtrl.openedQualityDate" 
   min-date="clCtrl.minDate" datepicker-options="clCtrl.dateOptions"  
   ng-required="true" close-on-date-selection="true" show-button-bar="false" />

将“只读”属性添加到输入字段:

<input type="text" readonly class="form-control" datepicker-popup="{{clCtrl.format}}" ng-model="clCtrl.QualityExpirationDate" is-open="clCtrl.openedQualityDate" min-date="clCtrl.minDate" datepicker-options="clCtrl.dateOptions" ng-required="true" close-on-date-selection="true" show-button-bar="false" />
然后使用“isValidDate”作用域属性显示/隐藏消息和/或禁用提交,或执行任何您想执行的操作


当然,最好将此验证抽象为一个指令,以便在您的所有日期字段上方便地重复使用。

我们将此功能提供给用户,以便用户手动输入日期以及从日历中选择。如果我们使用只读属性,则用户无法输入日期值,在这里,我们为用户提供了手动输入日期以及从日历中选择日期的功能。
<input type="text" readonly class="form-control" datepicker-popup="{{clCtrl.format}}" ng-model="clCtrl.QualityExpirationDate" is-open="clCtrl.openedQualityDate" min-date="clCtrl.minDate" datepicker-options="clCtrl.dateOptions" ng-required="true" close-on-date-selection="true" show-button-bar="false" />
$scope.$watch('dt', function(val) {
  $scope.isValidDate =  isNaN(new Date(val).getTime());
});