Mr. B. Mr. B. - 8 months ago 42
AngularJS Question

AngularJS + CSS: best practice for a live preview?

I've a textfield with a hex-color as it's value. I'd like to display the impact live, e.g. by changing the body's background-color.

The code works but feels wrong/dirty. I'd like to avoid jQuery's

and follow the angular principles.

<div data-ng-app>
<span data-ng-init="'#00FF00';"/>

<style type="text/css">
body {
background: {{}}; <!-- dirty ?! -->

<input type="text" data-ng-model=""/>

Does anyone know a good/clean solution? Thanks in advance!


You could use a change event on your input and use an ng-style on your body tag