I want to set one word in a sentence to have md-primary color, and another word to have the accent color. I assumed something like this:
<div>
Hello <span class="md-primary">friend</span>.
How are <span class="md-accent">you</span>?
</div>
But those classes work only for some specified components.
What's the way to do it?
I was just able to do this using Angular Material 1.1.0.
You use the
md-colors
directive similar to how you wouldng-class
:The above code will color the text the primary color. The object that you pass to
md-colors
uses the key as the css property (i.e. 'color', 'background', etc) and the value as the theme and/or palette and/or hue you want to use.Source Docs
The latests bits bring good news to this issue... This functionality has been added to the 1.1.0-rc3 (2016-04-13) version. It's not stable yet, but my first test on it are satisfactory.
Now you can use the mdColors directive and $mdColors service in conjunction with themes to achieve what you're looking for.
Please, take a look at:
https://github.com/angular/material/blob/master/CHANGELOG.md#110-rc3-2016-04-13
to see the announcement, and look for the mdColor directive and $mdColor service in the docs for some examples.
there is an issue in github that disccused this, like mentioned above TitForTat's comment in that issue almost had the perfect solution, but it doesn't work with costume palettes, i add a comment there with a fixed solution, you can check it out: https://github.com/angular/material/issues/1269#issuecomment-124859026
I think the only way is to create your own custom palette as demonstrated in the docs: https://material.angularjs.org/latest/#/Theming/03_configuring_a_theme under the paragraph Defining Custom Palette. There you can define 'contrastDefaultColor' to be light or dark. If I am correct, that should do it.
However, I want to use a standard palette and override the text color to light, not define a whole new palette.
You can also (and I would suggest this) extend an existing palette with 'extendPalette'. This way you wouldn't have to define all hue's but only set the 'contrastDefaultColor' accordingly.
*edit: just tested a solution
Add this to your config function (look for angular code example on link provided above about configuring theme)
I just set the 600 HUE to a green color to verify if the theme change works, so you can ignore that line in the extendPalette.
So this only changed the colour to light, not a specific colour. So it didn't answer your question, but might still come in handy.
For me i assume everything that starts with md- you can only apply theme colors to them.
In the documentation there are some components that are not documented where you can use theme colors. Example:
Angular Material's docs explicitly enumerate list of components, which you able to differentiate with
md-theme
attribute:From Angular Material documentation, under Theming / Declarative Syntax.
So I think the short answer is: you can't do it.