我想在一个页面上有几个日期选择器。但使用 UI-Bootstrap 的默认解决方案是不可能的,不会打开任何一个日期选择器。彼此之间的冲突。这是我的代码:
<div>
<div class="form-horizontal pull-left">
<input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt" is-open="opened" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true"/>
<button class="btn" ng-click="open()"><span class="glyphicon glyphicon-calendar"></span></button>
</div>
<div class="form-horizontal pull-left">
<input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt" is-open="opened" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" />
<button class="btn" ng-click="open()"><span class="glyphicon glyphicon-calendar"></span></button>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</div>
我刚刚从网站 http://angular-ui.github.io/bootstrap/#/datepicker 复制/粘贴了日期选择器代码。他们互相冲突。当我点击<input>
时打开日期选择器的字段没有人可以正确打开,两者都打开一秒钟然后立即消失。
如何在一个页面上拥有多个日期选择器?
最佳答案
您可以使用不同的 is-open
属性,然后通过 ng-click
函数传入该属性,而不是使用不同的函数。您仍然需要不同的模型:
<div>
<div class="form-horizontal pull-left">
<input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt1" is-open="opened1" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true"/>
<button class="btn" ng-click="open($event,'opened1')"><span class="glyphicon glyphicon-calendar"></span></button>
</div>
<div class="form-horizontal pull-left">
<input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt2" is-open="opened2" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" />
<button class="btn" ng-click="open($event,'opened2')"><span class="glyphicon glyphicon-calendar"></span></button>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</div>
以及内部 Controller :
$scope.open = function($event,opened) {
$event.preventDefault();
$event.stopPropagation();
$scope[opened] = true;
};
关于angularjs - 如何在一个页面上至少有两个 ui-bootstrap 的日期选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19613510/