javascript AngularJS ng-style 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22013818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 22:12:47 来源:igfitidea点击:
AngularJS ng-style is not working
提问by yasii
I am trying to apply background color on a div
using AngularJS ng-style
. My colors are coming from a database. It is not working for me. Can anybody help me.
我正在尝试在div
using AngularJS上应用背景颜色ng-style
。我的颜色来自数据库。它不适合我。有谁能够帮我。
<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>
采纳答案by Eugene P.
http://plnkr.co/edit/LV96s0szWbBFkzCCKfpJ?p=preview
http://plnkr.co/edit/LV96s0szWbBFkzCCKfpJ?p=preview
this is more like you need. take a look.
这更像是你需要的。看一看。