如何使用angular2启用/禁用下拉列表?

时间:2017-02-05 16:16:18

标签: javascript html angular

希望这不是一个重复的问题。我有一些布局如下,

<div class="btn-group">
    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Category <span class="caret"></span>
   </button>
   <ul class="dropdown-menu default-dropdown">
         <li><a href="#">Action</a></li>
         <li><a href="#">Another action</a></li>
         <li><a href="#">Something else here</a></li>
   </ul> 
 </div>

如何启用带有角度的按钮单击下拉列表?

1 个答案:

答案 0 :(得分:2)

启用/禁用

<div class="btn-group">
    <button [attr.disabled]="dropdownDisabled ? true : null" 
            type="button" class="btn btn-default dropdown-toggle" 
            data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Category <span class="caret"></span>
   </button>
   <ul class="dropdown-menu default-dropdown">
         <li><a href="#">Action</a></li>
         <li><a href="#">Another action</a></li>
         <li><a href="#">Something else here</a></li>
   </ul> 
 </div>

 <button (click)="dropdownDisabled = !dropdownDisabled">toggle</button>

打开/关闭

我假设您使用的是bootstrap css style

<div class="btn-group dropdown" [class.open]="dropdownOpened">
    <button (click)="dropdownOpened = !dropdownOpened"
            type="button" class="btn btn-default dropdown-toggle" 
            data-toggle="dropdown" aria-haspopup="true" 
            [attr.aria-expanded]="dropdownOpened ? 'true': 'false' ">
    Category <span class="caret"></span>
   </button>
   <ul class="dropdown-menu default-dropdown">
         <li><a href="#">Action</a></li>
         <li><a href="#">Another action</a></li>
         <li><a href="#">Something else here</a></li>
   </ul> 
 </div>