Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular2 dynamically change the style property value

Tags:

angular

I need to update a transform rotate value of image which dynamically change over the time

I tried something like below, but it isnt worked

style="transform: rotate(imagerotation ? imagerotation : 0 + deg);"

What is the proper way to achieve this ?

like image 540
Niyaz Avatar asked Oct 16 '16 02:10

Niyaz


People also ask

How do I change dynamic property in CSS?

color = "red"; you can apply the style change dynamically. Below is a function that turns an element's colour to red when you pass it the element's id . You could also use setAttribute(key, value) to set a style on an element. For example, you could set the colour of an element to red by calling element.

What is the difference between style and ngStyle?

ngStyle is an Angular directive that gives you the flexibility to do this, where as style is a regular HTML property to which you can only bind values one by one. That's the difference between the two of them.


1 Answers

Try this:

[style.transform]="'rotate(' + (imagerotation ? imagerotation : 0) + 'deg)'"
like image 194
Sasxa Avatar answered Sep 19 '22 17:09

Sasxa