I have this, which I would assume to work, but doesn't:
<mat-icon color="white">home</mat-icon>
Then, I also have:
<button mat-raised-button color="accent" type="submit"
[disabled]="!recipientForm.form.valid">
<mat-icon color="white">save</mat-icon>SAVE
</button>
This code snippet, for some reason, does work (shows the icon as white).
How do I get the lone mat-icon
to show up as white using the color
attribute? (I can easily just add a white class, but I want to understand this)
If you want to use Jquery$(". material-icons"). css("color", themeColor); This will change color of the material icons inside an element eg input field.
There does not seem to be option to change color of mat stepper icon, you can use this css as workaround. Custom theme class can be used across application,just wrapp any material component and use color attribute primary,accent or warn as defined in class.
To use Material icons in Angular, use <mat-icon> component. The <mat-icon> directive supports both icon fonts and SVG icons, but not bitmap-based formats. Icons are the necessary components when building modern-day web apps, and sometimes they can be frustrating.
That's because the color
input only accepts three attributes: "primary"
, "accent"
or "warn"
. Hence, you'll have to style the icons the CSS way:
Add a class to style your icon:
.white-icon {
color: white;
}
/* Note: If you're using an SVG icon, you should make the class target the `<svg>` element */
.white-icon svg {
fill: white;
}
Add the class to your icon:
<mat-icon class="white-icon">menu</mat-icon>
In the component.css or app.css add Icon Color styles
.material-icons.color_green { color: #00FF00; }
.material-icons.color_white { color: #FFFFFF; }
In the component.html set the icon class
<mat-icon class="material-icons color_green">games</mat-icon>
<mat-icon class="material-icons color_white">cloud</mat-icon>
ng build
Or simply
add to your element
[ngStyle]="{'color': myVariableColor}"
eg
<mat-icon [ngStyle]="{'color': myVariableColor}">{{ getActivityIcon() }}</mat-icon>
Where color
can be defined at another component etc
color="white"
is not a known attribute to Angular Material.
color attribute can changed to primary
, accent
, and warn
. as said in this doc
your icon inside button works because its parent class button has css class of color:white
, or may be your color="accent"
is white. check the developer tools to find it.
By default, icons will use the current font color
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