I am trying to use ng-class of angular. I have a function which returns the class based on the parameters we send it. How can i achieve it ?
Here's what i tried:
<div ng-class="{ getClass(key) }" >
and in the controller:
getClass = function(keyVal){
angular.forEach(myArray, function(value, id){
if(value.key === keyVal){
console.log(value.class);
return value.class;
}
});
}
Just returning a string works. but the moment I add this anfular.forEach, it stops. In debugger, the loop is working fine and returning the right data.
I know it can be acheved by a filter, but I want to do this way only.
See Question&Answers more detail:os