Calling functions in ngClass

0

I would like to call functions in ngClass. I can only call the function, and if I want to call other classes it does not catch, its just put the function in the class it can call (ng-class="styleClass (5)"), but I want some classes always and others can be changed by other validations. When I take the example function, it works fine.

Follow the example:

JavaScript

$scope.styleClass = function(i) {
  console.log("entrou");
  if(i>1){
      return 'bg';
  }
  return ''
}

HTML

First Name: <input type="text" ng-class="{'text':true, 'padd':true, 'styleClass(5)':true}" ng-model="firstName"><br>
    
asked by anonymous 30.07.2018 / 20:20

2 answers

1

I talked to some friends and found a way, which is

ng-class="[styleClass(5),{'text': true, 'padd': true}]"
    
30.07.2018 / 21:04
0

You can mix the class (with fixed classes) attribute with ng-class to return the function:

<input type="text" class="text padd" ng-class="styleClass(5)" ng-model="firstName">
    
30.07.2018 / 20:41