How do I use an expression with md-colors directive?
Asked Answered
M

1

9

I am using AngularJS Material and I would like to apply md-colors="" values based on an expression the same way an expression can be used with ng-class="". I have not been able to get this working.

Here's an example :

<md-button md-colors="{background:'accent-900-0.43' : mode == 'development'}" ng-click="setMode('development')">
development
</md-button>

The desired output is that the md-button will take on the accent-900 background color if the condition mode=='development' is true.

Can md-colors be used this way?

Maximamaximal answered 29/3, 2017 at 16:35 Comment(0)
I
13

you can use ternary operation inside md-color to assign styles

<md-button md-colors="mode == 'development' ? {background:'accent-900-0.43'} : {background:'whatever_condition_false_color'} " ng-click="setMode('development')">
development
</md-button>
Iambus answered 29/3, 2017 at 16:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.