【发布时间】:2023-03-26 07:42:01
【问题描述】:
在重新渲染 datepicker-popup 指令时,ui-datepicker 似乎没有考虑之前选择的模型值。
请查看此plunker,选择一个日期,然后将复选框切换两次以删除并重新创建日期选择器表单字段。
datepicker 表单字段值从 2014-12-14 更改为 Sun Dec 14 2014 16:21:46 GMT+0100 (CET)
<form class="form" name="test">
<legend>Anuglar ui datepicker and ng-if Test</legend>
<div class="form-group">
<label>
<input type="checkbox" ng-model="mymodel.namespace.showDate"/>
Show date
</label>
<pre>{{mymodel.namespace.date}}</pre>
</div>
<div class="form-group"
ng-if="mymodel.namespace.showDate === true "
>
<input
class="form-control"
name="date"
type="text"
ng-model="mymodel.namespace.date"
show-weeks="false"
show-button-bar="false"
is-open="calendarOpened"
ng-required="true"
ng-click="calendarOpened=true"
datepicker-popup />
</div>
</form>
// JS
app = angular.module('testApp', ['ui.bootstrap'])
app.controller('TestCtrl', function($scope){
$scope.mymodel = {
namespace: {
date: new Date(),
showDate: true
}
}
})
【问题讨论】:
-
我不确定您所描述的问题是什么。每次我单击一个日期,然后单击关闭选择器以关闭选择器,然后单击返回文本框以重新打开选择器,我之前选择的日期就存在了。
-
sorry my bad 没有记录最新版本的plunk,想看的赶紧更新
-
打开了一个github问题github.com/angular-ui/bootstrap/issues/3124
标签: angularjs datepicker