Mr. B. Mr. B. - 1 year ago 71
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!

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download