how to take the value of Dropdown in ng-bootstrap?

后端 未结 2 1827
深忆病人
深忆病人 2021-01-20 05:51

i\'m using ng-bootstrap and i want to get the value of dropdown when selected .

 
相关标签:
2条回答
  • 2021-01-20 06:10

    This runs without any javascript backend code. Solution is build upon angular template variables. Until no item is selected a place holder text "Select Environment" is displayed.

    <div ngbDropdown class="d-inline-block">
        <button class="btn btn-outline-primary" id="dropdown"
           ngbDropdownToggle>{{ selectedValue.value || "Select Environment" }}</button>
        <div ngbDropdownMenu aria-labelledby="dropdown" #selectedValue>
          <div *ngFor="let env of environments;" >
            <button ngbDropdownItem id="option" on-click="selectedValue.value=env">{{env}} 
            </button>
          </div>
        </div>
    </div>
    
    0 讨论(0)
  • 2021-01-20 06:30

    You need to add a click event:

     <button class="dropdown-item" (click)="changeAction(obj)">
    

    In the component:

    changeAction(obj) {
            //your logic here
    }
    
    0 讨论(0)
提交回复
热议问题