0

I have many many buttons in page and a input for user to enter color.

Is there a better way than below code?

<button ng-style="myStyles">
<button ng-style="myStyles">
.....
....

<input type="text" ng-modal="myStyles.color">

Can we generate a dynamic class like below?

<style>
 button {
     color : {{myStyles.color}}
 }
</style>
1
  • I assume you meant ng-model in your input (not ng-modal)? Commented Apr 24, 2015 at 4:17

3 Answers 3

3

Try the following...

<button ng-class="{color: myStyles.color}">   

<input type="text" ng-model="myStyles.color">

You can see a working example here.

Sign up to request clarification or add additional context in comments.

Comments

0

Easy and simple solution

<html>
<div id="a1">
<button>button 1</button><br/>
<button>button 2</button><br/>
<button>button 3</button><br/>
<input type="text" onkeyup="Fn1()" id="data" />
</div>
<script type="text/javascript">
function Fn1(){
    var z = document.getElementById("data").value;
    var x = document.getElementById("a1");
    var y = x.getElementsByTagName('button');   
    for(var i = 0;i<y.length;i++)
        {   
            y[i].style.color=z;

        }
}
</script>

</html>

Comments

0

Found the solution, a directive to interpolate inside tag http://alexbaden.me/interpreting-data-binding-in-style-tags-with-angular/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.