Javascript 使用ng模型选项更新:带uib日期选择器弹出窗口的模糊

Javascript 使用ng模型选项更新:带uib日期选择器弹出窗口的模糊,javascript,angularjs,twitter-bootstrap,datepicker,angular-ui-bootstrap,Javascript,Angularjs,Twitter Bootstrap,Datepicker,Angular Ui Bootstrap,我有一个输入,允许用户通过uib datepicker calendar()键入或选择日期。当用户单击输入时,会弹出日期选择器,允许用户进行选择。以下是输入: <input datepicker-append-to-body="calendarCtrl.appendToBody" uib-datepicker-popup="calendarCtrl.dateFormat" ng-model="calendarCtrl.ngModel" ng-clic

我有一个输入,允许用户通过uib datepicker calendar()键入或选择日期。当用户单击输入时,会弹出日期选择器,允许用户进行选择。以下是输入:

<input
     datepicker-append-to-body="calendarCtrl.appendToBody"
     uib-datepicker-popup="calendarCtrl.dateFormat"
     ng-model="calendarCtrl.ngModel"
     ng-click="calendarCtrl.open"/>
当用户在输入中键入日期时,这种方法非常有效——ngModel在出现模糊之前不会更新,任何验证在模糊之前都不会运行。问题是它破坏了日历弹出窗口的功能,当用户点击打开的日历选择日期时,什么也不会发生。我这样假设是因为当用户点击日历时,实际上输入上发生了一个模糊事件

有人遇到过这个问题吗?datepicker中是否有ng模型选项或其他选项,允许用户仍然从datepicker中进行选择,但在输入出现模糊之前不更新ng模型


谢谢

听起来您可以在日期选择器中为ngModel使用临时属性
ng model=“calendarCtrl.tempSelectedDate”

然后使用ngBlur事件()更新不动产,即set
calendarCtrl.ngModel=calendarCtrl.tempSelectedDate

此外,虽然没有什么可以阻止您在
ngModel
中使用scope属性
calendarctr.ngModel
,但如果您使用更有意义的名称,如
ng model=“calendarctr.dateSelected”
,代码将更易于阅读

这是一个工作演示


我分叉并扩展了其他人的日期选择器plnkr,做了两个更改:将
ng blur=“blurDate=startDate”
添加到
&使用
blur Date:{{{{blurDate}}

显示值,我添加了一个示例plnkrIn,在我的案例中,每次单击输入时都会调用ng blur,因为弹出的日历正在调用blur。在我的模糊函数中,我将ngModelController设置为$dirty,然后触发任何错误的验证。我最终通过监听输入元素上的键并将输入设置回$pristine来解决这个问题。然后,当用户单击日历弹出窗口或通过单击使输入模糊时,表单将设置回$dirty并查找验证错误。基于现有代码的黑客解决方案似乎是唯一的选择。
 ng-model-options={updateOn: 'blur'}