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)
color="white"
is not a known attribute to Angular Material.color attribute can changed to
primary
,accent
, andwarn
. as said in this docyour icon inside button works because its parent class button has css class of
color:white
, or may be yourcolor="accent"
is white. check the developer tools to find it.By default, icons will use the current font color
In the component.css or app.css add Icon Color styles
In the component.html set the icon class
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 etcThat's because the
color
input only accepts three attributes:"primary"
,"accent"
or"warn"
. In other words, you either:Set your theme as white for primary/ accent.styles.scss
:EDIT: If you view the list of palettes that are available in the
_palette.scss
file, there's no such$mat-white
palette variable being declared. As such, this approach is invalid.Use the class as shown below:
Or:
Just add a class to style your icon:
Add the class to your icon:
Since for some reason white isn't available for selection, I have found that
mat-palette($mat-grey, 50)
was close enough to white, for my needs at least.