1

i need to change button color into red (primary color to red color) after clicking button, please help me how to change color after clicking button.

 <td>
      <button mat-icon-button color="primary">
        <mat-icon>remove_circle</mat-icon>
      </button>
      </td>

3 Answers 3

8

Implement this logic in your code.

var isClicked = false;
.myClass{
  color : red;
}
<td>
      <button mat-icon-button color="primary" (click)="isClicked = !isClicked" [class.myClass]="isClicked">
        <mat-icon>remove_circle</mat-icon>
      </button>
      </td>

Sign up to request clarification or add additional context in comments.

3 Comments

@Richards, please let me know if it works for you or need further assistance :)
thank u @Harunur i am trying. .myClass{ color : red; } can i use these in component file.
Put this class in your component.css file or whichever style file you want.
2

Try this way

// .ts file  
flag : any = false;

btnClick(){
    this.flag = true;
}

Set css for color

::ng-deep .colorRed{
    color:red
}

In your HTML file

  // To apply color on row just put ngClass on tr  
  <tr [ngClass]="{ 'colorRed' :flag }">
    <td>
      <button mat-icon-button color="primary" (click)="btnClick()">
          <mat-icon>remove_circle</mat-icon>
       </button>
     </td>
  </tr>

2 Comments

thank you @sachin but whats happening means it should only change particular selected color but it is changing completed rows color. will you help me in these.
@Richards I have update my answer. Please look in to that. You just have to apply class on tr where you want to set as you can see in my answer. :)
0

Since you're using @angular/material, you should bind to the color @Input of their component rather than just adding a css-class of your own.

That way you do not have to worry about css-priority and your code will not be fragile to changes in the @angular/material implementation of component color.

  <button mat-icon-button 
          [color]="buttonColor"
          (click)="buttonColor = 'warn'">
    <mat-icon>remove_circle</mat-icon>
  </button>

and in your component

   buttonColor: ThemePalette = 'primary';

If your warn-color is not red, then consider changing your theme or making a new theme.

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.