css - 将 ng-repeat 值分配给样式属性

标签 css angularjs

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

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

Angular :

 $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}} 值设置背景颜色或宽度?

最佳答案

试试这个:

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

关于css - 将 ng-repeat 值分配给样式属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49446484/

相关文章:

html - 在CSS中将div元素转换为内联

javascript - 为什么 `on` 处理程序调用的顺序不按 Angular 排列?

javascript - 使用 ng-click 或 jquery 检测平板电脑上的长按

ASP.NET Visual Studio 不捕获更改 - 从临时文件编译

html - 垂直对齐,让我同样头疼

css - CSS 星号选择器是否被认为是有害的(为什么)?

javascript - 如何在angularjs中执行路由

javascript - 如何在可用时使 Angular.js 应用离线并与服务器同步

AngularJs 复选框难题

html - 如何从左到右创建动画或制作淡入淡出的 Angular 4