lega911 / angular-light

Alight is a library for building interactive MVVM web interfaces/applications. (project is deprecated)
MIT License
274 stars 43 forks source link

How to pass object to :style? #249

Closed Ni55aN closed 7 years ago

Ni55aN commented 7 years ago

There is ability to pass object with multiple properties in v0.14 ?

What I need:

al-init="myStyle="{backgroundColor: 'red'}"
...
:style="myStyle"

but it does not work in 0.14 (before that I used al-style and everything worked http://jsfiddle.net/vxhdcj3f/1/)

Ni55aN commented 7 years ago

Made the conversion of the object into a string manually, but this makes the code heavier

http://jsfiddle.net/vxhdcj3f/2/

lega911 commented 7 years ago

Hello!

it was deprecated 1) usually you don't need it (I've never used it in real) 2) it requires deep-watch (it's slower than simple watch) 3) ugly api

instead you can use :style for different props, like:

<div 
    :style.background-color="color"
    :style.border-color="color">

example: https://jsfiddle.net/uzjgowmg/

also in majority of cases, :class is used, or if you need something complex you can use (direct) directive.

Ni55aN commented 7 years ago

@lega911 thanks for the quick response. I did it using directive and deep watching