1

If i click the button it will change the color in to orange but by requirement is after click the same button it need to change into default color. so please guid me to do this.

  <button #val1 class="mat-raised-button" [ngClass]="{'orange': val1.value==current_product_size}" (click)="sizeFilter(val1.value)" value="375ML">375ML</button>

Component.ts

sizeFilter(size_clicked) {
    this.current_product_size = size_clicked
}
1
  • P.S. You're supposed to use the mat-raised-button attribute instead of the class. This is to apply the appropriate ripple. (Unless if you don't want the ripple - use the disableRipple attribute)' Commented Nov 30, 2018 at 11:03

2 Answers 2

2
**You can give more than one ngClasses if you want like this** 


<button #val1 class="mat-raised-button" 
[ngClass]="{'toggleColor': toggleColor,'orange': val1.value==current_product_size}" 
(click)="sizeFilter(val1.value)" 
value="375ML">375ML</button>

Component

toggleColor = false;
sizeFilter(size_clicked) {
this.toggleColor = !this.toggleColor;
this.current_product_size = size_clicked
}  

CSS

.toggleColor{
  background: yourDefaultColor !important;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Your html:

 <button #val1 class="mat-raised-button" [ngClass]="{'orange': isOrange}" (click)="setOrange()">375ML</button>

Your component:

isOrange = false;

setOrange() {
    isOrange = !isOrange;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.