(Angular+Bootstrap)如何阻止两个日期选择器被同一按钮打开
(Angular + Bootstrap) How to stop two datepickers from being opened by the same button
我有一个网页,需要两个日期选择器,开始日期和结束日期。问题是,每当我点击字形打开日期选择器时,两个日期选择器都会同时打开。
这是我的模板,指令,控制器和它是如何使用的。任何帮助都将不胜感激。
模板:
<div class="input-group">
<input type="text" class="form-control" uib-datepicker-popup="dd/MM/yyyy" ng-model="start_date" is-open="popup.opened" datepicker-options="dateOptions" ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open()">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
</div>
指令:
'use strict';
/*global angular*/
angular.module("myApp")
.directive("datepicker", function(){
return{
templateUrl: 'templates/datePicker.html',
controller: 'newDateCtrl',
replace: true
};
});
控制器
/*global angular*/
angular.module("myApp").controller("newDateCtrl", function($scope) {
$scope.popup = {
opened: false
};
$scope.open = function() {
$scope.popup.opened = true;
};
$scope.dateOptions = {
formatYear: 'yy',
maxDate: new Date(2020, 5, 22),
minDate: new Date(),
startingDay: 1
};
})
index.html,作为如下表单的一部分:
....
<div class="form-group">
<label class="control-label col-sm-2">
Start Date
</label>
<div class="col-sm-10">
<datepicker></datepicker>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">
End Date
</label>
<div class="col-sm-10">
<datepicker></datepicker>
</div>
</div>
....
两件事:-在声明指令时,请使用隔离作用域。
即
.directive('...', function() {
return {
.... // your existing stuff
scope: {} // this gives each directive instance isolated scope
}
});
- 我认为"datepicker"已经是引导指令的名称,所以如果你要包装它,你应该考虑给它一个不同的名称
相关文章:
- 如何禁用引导程序时间选择器中的按钮
- 从GWT中的HighCharts库(以及一般的Javascript)自定义Stockchart范围选择器按钮
- JQuery IE11 单选按钮选择器
- 如何在jQuery的.on()方法中动态更新按钮的ID选择器
- 为什么当我单击打印按钮时@media打印选择器没有显示正确的格式
- (Angular+Bootstrap)如何阻止两个日期选择器被同一按钮打开
- 当页面上有多个具有相同选择器的按钮时,请检查单击了哪个exatly按钮
- 如何将剑道日期选择器的焦点更改为另一个按钮?i
- 单击按钮时显示日期选择器
- Bootstrap日期选择器setDatesDisabled无法处理按钮单击
- 如何为表单提交添加选择器,仅当特定按钮类型导致表单提交时
- jQuery选择器<按钮></按钮>
- 一旦使用了jQuery日期选择器,无法使“保存更改”按钮不灰
- 为什么高库存范围选择器中有禁用的按钮
- jQuery 日期选择器在单击按钮时不起作用
- 制作 JavaScript 按钮选择器
- Python 硒提交按钮在日期选择器后不起作用
- :按钮选择器在火狐和IE中不起作用
- Jquery单选按钮选择器
- 按钮选择器 --> 将数字添加到表单中的输入