Topic: How to define a button that has a selected and unselected state?

davout free asked 4 years ago


I want to include in my toolbar a button that have a distinct 'selected' /'unselected' state The aim is to use the button to show and hide a side panel on the web page

Any suggestions?


Arkadiusz Idzikowski staff answered 4 years ago


You can create a variable and update its value on button click, for example:

<button mdbBtn color="primary (click)="onClick()">Button</button>

Then in your typescript code:

buttonSelected = false;

onClick() {
    this.buttonSelected = !this.buttonSelected; // update selected state

    if (buttonSelected) {
     // do something
    } else {
    // do something
    }
}


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 8.8.1
  • Device: PC
  • Browser: Chrome
  • OS: Windows10
  • Provided sample code: No
  • Provided link: No