css属性不加载

时间:2016-06-21 16:11:15

标签: css angularjs document-ready

我需要在angular controller.js文件中为css属性设置标签的background属性。 我正在使用jquery来更新背景。 下面是我的代码:如果$ scope.isInside为true,我需要一种颜色,如果为false,我需要另一种颜色。此.norow应用于HTML中的DIV。 问题是它不能始终如一地运作。有时候背景颜色会被设定,有时却不会。

angular.element(document).ready(function () {
    if ($scope.isinside){
        $(".norow label").css("background-color","#ffffdd");
    }
    else{
        $(".norow label").css("background-color","#ffffff");
    }
});

1 个答案:

答案 0 :(得分:0)

尝试ng-style:

<label ng-style="{'background-color': isinside ? '#ffffdd': '#ffffff'}" > something </label>

您也可以使用ng-class:

<label ng-class="{'grey-bg': isinside, 'white-bg': !isinside}"> something </label>