我有一个坐在ng-repeat中的bootstrap ui datepicker。因此,用户可以根据需要添加任意多的行,这将导致日期选择器的多个实例。我为多个日期选择器看到的所有示例仅显示您是否有两个,并且在将它们应用于动态情况时解决方案不起作用。
打开日期选择器的属性是is-open =“ open”,并且open应该是唯一的,因此我需要一种方法来关闭所有日期选择器,仅打开我选择的日期选择器。切记,每个都是动态构建的。
这是转发器中使用的代码。
<div class="input-group">
<input type="text" class="form-control" name="birthdate" datepicker-popup="{{format}}" ng-model="cabins[$parent.$index].passengers[$index].birth_date" is-open="cabins[$parent.$index].passengers[$index].datePicker" min-date="minDate" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event,$parent.$index,$index)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</div>
使用ng-repeat $ index,is-open“ $ parent.viewModel.openIndex === $ index”并在open事件中分配viewModel.openIndex:ng-click =“ $ parent.viewModel.openIndex = $ index” 。请注意,使用了$ parent,这样做是为了访问ng-repeat范围内的视图模型范围。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句