【问题标题】:assign ng-repeat value to style property将 ng-repeat 值分配给样式属性
【发布时间】:2018-09-01 22:37:56
【问题描述】:

我有一个 ng-repeater,它通过一个角度类成功地从控制器获取值。但是,我有一个 double 值,我试图将其分配给 div 的样式。 是否可以将返回的 ng-repeat 值分配给 div 的 style 属性?

<div class="panel panel-default" ng-controller="HomeController" ng-init="init()">
<pre>{{ClockLogic}}</pre>
<br />
<br />
<div id="containerDiv" style="width: 100%;">
    <div id="clockDiv" style="width: 800px;" ng-repeat="clock in ClockLogic">
            <div class="row" id="clockwidget" style="background-color: "{{clock.LogicColor}};">
                <p>hello</p>
            </div>

        </div>
    </div>

角度:

 $scope.ClockLogic = [{
        LogicID: '',
        LogicClockWidth: '',
        LogicMaxWidth: '',
        LogicColor: ''
    }]

    $http.get('/Home/SetClockTimes')
        .then(function (response) {
            $scope.ClockLogic = response.data;
            console.log("status:" + response.status);
            console.log("data: " + $scope.ClockLogic);

        }).catch(function (response) {
            console.error('Error occurred:', response.status, response.data);
        }).finally(function () {
            console.log("Task Finished.");
        });

谁能帮我根据{{clock}} 值设置背景颜色或宽度?

【问题讨论】:

标签: css angularjs


【解决方案1】:

试试这个:

<div class="panel panel-default" ng-controller="HomeController" ng-init="init()">
<pre>{{ClockLogic}}</pre>
<br />
<br />
<div id="containerDiv" style="width: 100%;">
    <div id="clockDiv" style="width: 800px;" ng-repeat="clock in ClockLogic">
            <div class="row" id="clockwidget" ng-style="{'background-color': clock.LogicColor}">
                <p>hello</p>
            </div>

        </div>
    </div>

【讨论】:

  • 谢谢!!这正是我所需要的。感谢您的快速响应和帮助。
猜你喜欢
  • 1970-01-01
  • 2015-06-09
  • 1970-01-01
  • 2016-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-25
相关资源
最近更新 更多