Bs datepicker的值更新但显示值不更新
Bs datepicker's value updates but display value does not update
angularjs的版本是1.5.11。
我在我的 .NET MVC 项目中使用 angularjs 中的 bs-datepicker 元素。这是我的日期选择器和一些在我的应用程序中用作按钮的图像:
<input class="form-control"
type="text"
placeholder="Pick a Date (default today)."
data-date-format="MM-dd-yyyy"
data-min-date="today"
bs-datepicker
data-autoclose="true"
ng-model="tos.appointmentDay"
ng-change="tos.updateAppointments()"
style="width: 100px;" />
<div class="appointment-buttons">
<i class="fa fa-arrow-left fa-lg"
ng-click="tos.decrementAppointmentDate()" />
<i class="fa fa-arrow-right fa-lg"
ng-click="tos.incrementAppointmentDate()" />
</div>
我有两个箭头图像元素被用作按钮,以在我的约会应用程序中将某一天向前或向后更改一天。这些按钮确实会与此日期选择器一起正确更改日期(通过在我的控制器中使用我的功能),我可以看到它反映在我的代码中显示日期的日期选择器弹出窗口和其他文本输出中。
但是,当我通过两个箭头按钮更新我的应用程序中约会日期 属性 的值时,我的所有输出都会更新,包括日期选择器的实际值,但文本中的显示值日期选择器的输入字段不会更新。为什么弹出窗口中日期选择器的值会正确更新,但 bs-datepicker 的文本输入字段不会更新?
解决方案是,当您在 JavaScript/TypeScript 中对绑定到元素(在本例中为日期选择器)的日期对象执行 setDate 调用时,它不会更新数据选择器。这是因为您需要显式分配已绑定到元素的对象以更改它们的值。 bs-datepicker 元素和 angularjs.
元素都是如此
你应该:
//Do this.
var temp = original;
temp.setDate(newDate);
original = temp;
//Don't do this by itself.
original.setDate(newDate);
angularjs的版本是1.5.11。
我在我的 .NET MVC 项目中使用 angularjs 中的 bs-datepicker 元素。这是我的日期选择器和一些在我的应用程序中用作按钮的图像:
<input class="form-control"
type="text"
placeholder="Pick a Date (default today)."
data-date-format="MM-dd-yyyy"
data-min-date="today"
bs-datepicker
data-autoclose="true"
ng-model="tos.appointmentDay"
ng-change="tos.updateAppointments()"
style="width: 100px;" />
<div class="appointment-buttons">
<i class="fa fa-arrow-left fa-lg"
ng-click="tos.decrementAppointmentDate()" />
<i class="fa fa-arrow-right fa-lg"
ng-click="tos.incrementAppointmentDate()" />
</div>
我有两个箭头图像元素被用作按钮,以在我的约会应用程序中将某一天向前或向后更改一天。这些按钮确实会与此日期选择器一起正确更改日期(通过在我的控制器中使用我的功能),我可以看到它反映在我的代码中显示日期的日期选择器弹出窗口和其他文本输出中。
但是,当我通过两个箭头按钮更新我的应用程序中约会日期 属性 的值时,我的所有输出都会更新,包括日期选择器的实际值,但文本中的显示值日期选择器的输入字段不会更新。为什么弹出窗口中日期选择器的值会正确更新,但 bs-datepicker 的文本输入字段不会更新?
解决方案是,当您在 JavaScript/TypeScript 中对绑定到元素(在本例中为日期选择器)的日期对象执行 setDate 调用时,它不会更新数据选择器。这是因为您需要显式分配已绑定到元素的对象以更改它们的值。 bs-datepicker 元素和 angularjs.
元素都是如此你应该:
//Do this.
var temp = original;
temp.setDate(newDate);
original = temp;
//Don't do this by itself.
original.setDate(newDate);