我仅在条件满足时才打开下拉列表。我怎样才能做到这一点?现在我的代码如下:
<div class="btn-group" uib-dropdown>
<button class="btn btn-secondary" uib-dropdown-toggle ng-click="vm.openDropdown()">
open
</button>
<div class="dropdown-menu dropdown-menu-right" uib-dropdown-menu>
<a class="dropdown-item d-inline-flex" ng-repeat="test in vm.tests">{{test}}</a>
</div>
</div>
vm.openDropdown = openDropdown
vm.tests = [1, 2, 3, 4]
function openDropdown () {
if (vm.test == true) {
////and here I need have condition if something is true, I do not want to open dropdown
}
}
答案 0 :(得分:1)
您是否尝试过使用ng-disabled
:(如果变量test为true,则无法打开下拉菜单)
<div class="btn-group" uib-dropdown>
<button class="btn btn-secondary" uib-dropdown-toggle ng-disabled="vm.test">open
</button>
<div class="dropdown-menu dropdown-menu-right" uib-dropdown-menu>
<a class="dropdown-item d-inline-flex" ng-repeat="test in vm.tests">{{test}}</a>
</div>
</div>