Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular-material change checkbox color

I'm using checkbox of angular-material2. Currently the default color of checkbox is coming as purple color.
Looks like they have changed default color of checkbox from "primary" to accent.
Is there a way to get "primary"(green) color instead of purple without overriding css.
I tried giving color="primary" to but that didn't worked.

Code : <md-checkbox></md-checkbox>

Import statement:

import {MdCheckbox} from '@angular2-material/checkbox'; 

Plunker http://plnkr.co/edit/sFC0kfdzj7fxtUC3GXdr?p=preview

like image 947
Krishna Avatar asked May 20 '16 06:05

Krishna


People also ask

How to change checkbox background color in angular material?

Explanation: The checked background color is changed to mat-checkbox-background within mat-checkbox-checked. IF you want to modify the background color when it is not checked just copy that part and copy it outside of mat-checkbox-checked.

How do I change the color of a checkbox?

“:hover” is used to style the checkbox when user hovers over it. Notice that when the mouse pointer move over the checkbox the color of it changes to yellow. “:active” is used to style the checkbox when it is active. Notice that when click the checkbox it will first notice a red color and then the green color.

How do I uncheck a checkbox in angular 6?

First mistake you made is you are adding (change) event on button click. Replace it with (click) as change event if for input type properties and you can only use it with ngModel. You should add isChecked property inside appUserRoleList list, which will help you to check/uncheck checkbox.


2 Answers

You don't have to add css if you'r using theme, just add attribute color to <mat-checkbox>

<mat-checkbox color="primary">Primary</mat-checkbox>

The color of a <mat-checkbox> can be changed by using the color property. By default, checkboxes use the theme's accent color. This can be changed to 'primary' or 'warn' Checkbox | Angular Material

like image 188
Khan Abdulrehman Avatar answered Sep 20 '22 16:09

Khan Abdulrehman


For Angular Material 7, works for outline color and inside filled in color

::ng-deep .mat-checkbox-checked.mat-accent .mat-checkbox-ripple .mat-ripple-element {     opacity: 0.03 !important;     background-color: #005691!important;   }  ::ng-deep .mat-checkbox-checked.mat-accent .mat-checkbox-background,.mat-checkbox-indeterminate.mat-accent .mat-checkbox-background {     background-color: #005691;   } 
like image 45
abstractME Avatar answered Sep 20 '22 16:09

abstractME