I have one button, i want to apply a default style of a button and when user click on a button change a button style color to red and background-color to white. Blow is my .css and component.
.btn-default {
  color: white;
  background-color: blue;
}
.btn-change {
  color: Red;
  background-color: white;
}
Component.ts
import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  bntStyle: string;
  AppComponent() {
   this. bntStyle = 'btn-default';
  }
  submit() {
    this.bntStyle = 'btn-change';
  }
.html
<div>
 <button name="Save" [ngClass]="['bntStyle']" (onClick)="submit()">Submit</button>
</div>
                Use the :hover selector to change the style of a button when you move the mouse over it.
This means that there is a drawable called btn_default set as button background. Now we need to find a file named btn_default. * in one of the drawable folders under android-sdk\platforms\android-15\data\res . This can be either an image (very unlikely) or a xml file like btn_default.
To change the background color of the button, use the CSS background-color property and give it a value of a color of your taste. In the . button selector, you use background-color:#0a0a23; to change the background color of the button.
You are binding the string 'btnStyle'. Instead, you should bind the filed:
<div>
    <button name="Save" [ngClass]="[bntStyle]" (click)="submit()">Submit</button>
</div>
                        Fire change (OnClick) to (click) and then use following code snippet.
<div>
 <button name="Save" [ngClass]="[bntStyle]" (click)="submit()">Submit</button>
</div>
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With