How to configure NgbDropdown to display the selected item from the dropdown

后端 未结 2 454
清酒与你
清酒与你 2021-01-04 03:06

In ng-bootstrap NgbDropdown, how would you display the text of the selected button so that what ever item the user selects replaces the default text initially shown?

2条回答
  •  暖寄归人
    2021-01-04 03:25

    I solved this by hooking into the on-click event of the selected button ( using the blur event doesn't work in Firefox) - Plunkr demo

    The component:

    export class NgbdDropdownBasic {
        displayMessage = "Sort by...";
        sortOptions = ["Balance", "Company", "Last Name"]
    
        changeMessage(selectedItem: string){
           this.displayMessage = "Sort by " + selectedItem;
         }
     }
    

    The template with NgbDropdown:

     

提交回复
热议问题