繁体   English   中英

AngularJS ng-style无效

[英]AngularJS ng-style is not working

我正在尝试使用AngularJS ng-stylediv上应用背景颜色。 我的颜色来自数据库。 它不适合我。 有谁能够帮我。

<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>

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM