2017-02-05 74 views
0

希望這不是一個重複的問題。我有一些佈局如下,如何使用angular2啓用/禁用下拉菜單?

<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> 

如何啓用下拉按鈕點擊角?

+0

你的意思是打開/關閉或啓用/禁用? –

+0

@GünterZöchbauer抱歉打開關閉 – Sajeetharan

回答

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> 

打開/關閉

我假設你正在使用的引導CSS樣式

<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> 
+0

我認爲他想做一些行爲像引導下拉(打開/關閉下拉列表) –

+0

@TiepPhan謝謝。似乎我把這個問題的字面意思:D –

+1

我改變了你的代碼,基於引導CSS樣式 –