Use a function in ng-class in angular js

后端 未结 1 648
暗喜
暗喜 2021-01-26 05:23

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.

<
1条回答
  •  死守一世寂寞
    2021-01-26 05:46

    You need an array of classes, where one element of an array can be an object of classes with conditions and the other is your function call. A simple example would be:

    ng-class="[{'some_class' : condition}, function_class()]"
    

    Here is a demo:

    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
      $scope.bb = function() {
        return "b";
      }
    });
    .a {
      color: #999999;
    }
    
    .b {
      background-color: #F1F1F1;
    }
    
    .c {
      font-size: 30px;
    }
    
    

    A: color : #999999
    C: font-size : 30px

    Testing classes


    For your example I think you need:

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

    0 讨论(0)
提交回复
热议问题