I am trying to apply background color on a div
using AngularJS ng-style
. My colors are ing from a database. It is not working for me. Can anybody help me.
<div ng-controller="IndexCtrl">
<div style="width: 500px;">
<table class="table table-striped table-bordered table-condensed table-hover">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Edit</th>
</tr>
</thead>
<tbody ng-repeat="color in colors">
<tr ng-show="edit">
<td><input type="text" ng-model="color.ID" ng-change="color.changed=true" /></td>
<td>
<input type="text" ng-model="color.Name" colorpicker ng-change="color.changed=true" />
</td>
<td><input type="button" class="btn btn-primary" value="Save" ng-click="edit=false; save();" /> </td>
</tr>
<tr ng-hide="edit">
<td><strong>{{color.ID}}</strong> </td>
<td><div style="width:20px; height:20px; border:thin solid black" ng-model="color.Name" ng-style="{'background-color' : color.Name}"></div> </td>
<td><input type="button" class="btn btn-primary" value="Edit" ng-click="edit=true;" /></td>
</tr>
</tbody>
</table>
</div>
</div>
I am trying to apply background color on a div
using AngularJS ng-style
. My colors are ing from a database. It is not working for me. Can anybody help me.
<div ng-controller="IndexCtrl">
<div style="width: 500px;">
<table class="table table-striped table-bordered table-condensed table-hover">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Edit</th>
</tr>
</thead>
<tbody ng-repeat="color in colors">
<tr ng-show="edit">
<td><input type="text" ng-model="color.ID" ng-change="color.changed=true" /></td>
<td>
<input type="text" ng-model="color.Name" colorpicker ng-change="color.changed=true" />
</td>
<td><input type="button" class="btn btn-primary" value="Save" ng-click="edit=false; save();" /> </td>
</tr>
<tr ng-hide="edit">
<td><strong>{{color.ID}}</strong> </td>
<td><div style="width:20px; height:20px; border:thin solid black" ng-model="color.Name" ng-style="{'background-color' : color.Name}"></div> </td>
<td><input type="button" class="btn btn-primary" value="Edit" ng-click="edit=true;" /></td>
</tr>
</tbody>
</table>
</div>
</div>
Share
Improve this question
edited Sep 30, 2014 at 9:36
Steve
9,5005 gold badges48 silver badges62 bronze badges
asked Feb 25, 2014 at 12:10
yasiiyasii
331 gold badge1 silver badge5 bronze badges
12
- Is colorpicker a directive you wrote? – John Munsch Commented Feb 25, 2014 at 12:13
- can you create a fiddle? – doodeec Commented Feb 25, 2014 at 12:22
-
btw. what's up with defining
ng-model
on adiv
element? I have seen it a couple times now but I don't quite get what it's supposed to do. – doodeec Commented Feb 25, 2014 at 12:23 - I more than believe that ng-repeat on tbody is incorrect. – Eugene P. Commented Feb 25, 2014 at 12:56
- Yes colorpicker is a directive – yasii Commented Feb 25, 2014 at 13:00
1 Answer
Reset to default 2http://plnkr.co/edit/LV96s0szWbBFkzCCKfpJ?p=preview
this is more like you need. take a look.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745331527a4622900.html
评论列表(0条)