AngularJS ng-style无效

时间:2014-02-25 12:10:42

标签: javascript angularjs

我正在尝试使用AngularJS divng-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>

1 个答案:

答案 0 :(得分:3)

http://plnkr.co/edit/LV96s0szWbBFkzCCKfpJ?p=preview

这更像是你需要的。看一看。