I am using ng-class for adding the CSS classes. Even though there are lots articles on this, I am not able to add a function call with ng-class.
I have a following expression.
ng-class="{'highlighter-row-Class' : (file.id == 1 && file.processed),
'bold-row-Class' : lastSelectedResumeId == file.attributes.name,
'failed-doc': !file.processed}"
Now, multiple classes can get added. However, I want to add one more condition here, which will call a method and return a class name:
$scope.getclass = function() {
return 'someclass';
}
My attempt used this method in ng-class after the last condition, but it wasn't working. So, can anyone please tell me how I can do it correctly with ng-class?
Another attempt (after suggestions):
ng-class="[{'highlighter-row-Class' : (file.id == 1 && file.processed),
'bold-row-Class' : lastSelectedResumeId == file.attributes.name,
'failed-doc': !file.processed }, getClassForHrms(file)]"
Function:
$scope.getClassForHrms = function (file) {
if (file.attributes.hrmsMandatoryFieldsMissing) {
return "missingfieldspresent";
} else if (file.attributes.isDocumentDuplicated) {
return "documentduplicate";
} else if (!file.attributes.isDocumentDuplicated) {
return "documentuploadfailed";
}
};
Used CSS:
.missingfieldspresent {
color: red;
}
.documentduplicate {
color: purple;
}
.documentuploadfailed {
color: deeppink;
}
This is what the resulted HTML renders
<tr ng-repeat="file in processResumeFiles" ng-class="[{'highlighter-row-Class' : (file.id == 1 && file.processed),
'bold-row-Class' : lastSelectedResumeId == file.attributes.name,
'failed-doc': !file.processed }, getClassForHrms(file)]"
class="ng-scope [object Object] documentduplicate">
class="{{ getclass() }}"?