【问题标题】:ng-class not working with object and string [duplicate]ng-class 不适用于对象和字符串 [重复]
【发布时间】:2018-05-17 13:42:48
【问题描述】:

我是 Angular js 的新手。我用过 ng-class.here,

ng-class="[{'highlighter-row-Class' : (file.id == 1 && file.processed),
    'bold-row-Class' : lastSelectedResumeId == file.attributes.name, 
    'failed-doc': !file.processed }, getClassForHrms(file)]"

css

.missingfieldspresent {
  color: red;
}
.documentduplicate {
  color: purple;
}
.documentuploadfailed {
  color: deeppink;
}

功能

$scope.getClassForHrms = function (file) {
    if (file.attributes.hrmsMandatoryFieldsMissing) {
        return "missingfieldspresent";
    } else if (file.attributes.isDocumentDuplicated) {
        return "documentduplicate";
    } else if (!file.attributes.isDocumentDuplicated) {
        return "documentuploadfailed";
    }
};

呈现的 Html

<tr ng-repeat="file in processResumeFiles" ng-class="[{'highlighter-row-Class' : (file.id == 1 &amp;&amp; file.processed), 
    'bold-row-Class' : lastSelectedResumeId == file.attributes.name, 
    'failed-doc': !file.processed }, getClassForHrms(file)]" 
    class="ng-scope [object Object] documentduplicate">

现在,正在发生的事情是获取对象,因此没有添加该类。有没有办法使用那个类。

我该怎么做?

【问题讨论】:

  • 分而治之。当你有少量代码,但问题的根源完全不清楚时,开始一点一点地删除代码,直到问题消失– 然后添加最后一部分。

标签: javascript jquery css angularjs


【解决方案1】:

我认为 ng-class 的语法有点错误(去掉方括号)。

ng-class="{'highlighter-row-Class' : (file.id == 1 && file.processed), 'bold-row-Class' : lastSelectedResumeId == file.attributes.name, 'failed-doc': !file.processed }, getClassForHrms(file)"

【讨论】:

    猜你喜欢
    • 2016-05-20
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多