angularjs - 如何在一个页面上至少有两个 ui-bootstrap 的日期选择器?

标签 angularjs datepicker angular-ui-bootstrap

我想在一个页面上有几个日期选择器。但使用 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/

相关文章:

javascript - 在同一页面中包含两个 jquery 库

javascript - Bootstrap datepicker - 在特定月份的指定日期添加工具提示

angularjs - 如何使用 Angular 的 UI Bootstrap 分页指令进行服务器端分页

angularjs - 使用 angularjs 显示加载图标或加载进度条

angularjs - Angular UI Bootstrap 模块未关闭后退按钮

javascript - Angular 中 Promise 对象的回顾

html - Angular : Incorrect Alignment using ng-repeat and ng-include

javascript - 在 Datepicker 中将日期格式更改为 yyyy-mm-dd

angularjs - 如何更好地以 Angular 组织动态加载指令?

javascript - Angular Material 1.1.1 布局填充问题与指令