javascript - AngularJS ng-style is not working - Stack Overflow

I am trying to apply background color on a div using AngularJS ng-style. My colors are ing from a datab

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 a div 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
 |  Show 7 more ments

1 Answer 1

Reset to default 2

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

this is more like you need. take a look.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745331527a4622900.html

相关推荐

  • javascript - AngularJS ng-style is not working - Stack Overflow

    I am trying to apply background color on a div using AngularJS ng-style. My colors are ing from a datab

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信