Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add multiple condition in the ng-style

Tags:

angularjs

I need to add multiple condition in the ng-style. How can I do this?

I tried below code but it is not working.

ng-style="ifTrue?'opacity:1;' : 'ifTrue? 'opacity: 1;': 'opacity: 0.5;''"
like image 379
User7723337 Avatar asked Dec 29 '25 21:12

User7723337


2 Answers

You can simply separate your conditions with ",". Something like this:

ng-style="{ 'background-color': '#ff0', color: 'red' }"

See this example: http://jsbin.com/fabisepede/edit?html,output


Always remember to put quotes on "dashed" word ('background-color').

For the value you can also use variables defined in your controller and assign the style conditionally, but for that i prefer ng-class.

like image 156
eliagentili Avatar answered Jan 01 '26 17:01

eliagentili


You could use something like

ng-style="condition && { /*properties*/ } || condition2 && { /*other properties*/ }"

like image 38
taguenizy Avatar answered Jan 01 '26 18:01

taguenizy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!