Angular UI:下拉列表无法使用datepicker

时间:2015-10-14 12:36:24

标签: angularjs datepicker angular-ui angular-ui-bootstrap

我正在尝试在下拉列表中添加Datepicker,如下所示并设置了autoClose =“outsideClick”。但是,当按下任何月份按钮时,它会切换下拉列表。怎么解决这个问题?

Html代码:

<div class="date-wrap pull-right" dropdown auto-close="outsideClick">
                <button class="btn btn-info" dropdown-toggle>Date Picker</button>
                <div class="dropdown-menu  datepicker" role="menu">
                        <datepicker show-weeks="false" ng-model="dt"></datepicker>
                </div>
</div>

Plunker http://plnkr.co/edit/lBn3Oo?p=preview

1 个答案:

答案 0 :(得分:7)

您需要手动阻止点击事件冒泡,因此它永远不会到达关闭下拉列表的最顶层节点(文档):

<div class="date-wrap pull-right" dropdown auto-close="outsideClick">
    <button class="btn btn-info" dropdown-toggle>Date Picker</button>
    <div class="dropdown-menu  datepicker" role="menu" ng-click="$event.stopPropagation()">
        <datepicker show-weeks="false" ng-model="dt"></datepicker>
    </div>
</div>

注意,ng-click="$event.stopPropagation()"可以解决问题。

演示: http://plnkr.co/edit/pPwW83Ro0u0g4dVhyZaZ?p=info