Button click color


#1

hi guys,
have one question
i hv a button in side menu to show/hide a div
now i want to change its color on click
here is my html

<button menuClose ion-item (click)="door()"> Door </button>
<button ion-item (click)="showMovementReport()" [ngStyle]="{'background-color': buttonColor}"> Get Movement Report </button>
      <div *ngIf="toggled" >
          <button style="background-color:rgb(0, 124, 0)" *ngFor="let item of getMovementPages" ion-item no-lines> {{item.title}} </button>
      </div>

on click showMovementReport() function its shows/hide this div
i want to change the button color:
if div shows( on click showMovementReport()) then change color to orange
or
if div hides( on click showMovementReport()) then remove orange color/ or back to previous color
my button color changed when div shows but not changing if div hides
here is ms ts code:

toggled: boolean;
buttonColor: string;

showMovementReport() {
    this.buttonColor = '#345465';
    this.toggled = this.toggled ? false : true;
  }

#2

Modify your showMovementReport like this

showMovementReport() {
if(this.toggled){
     this.buttonColor = '#345465';
     this.toggled = false;
}
else{
     this.buttonColor = '#ffffff'; //hex code for previous color
     this.toggled = true;
}
  }

#3

thank u so much Ankit_Makwana.