0

I am using Angular directives for KendoUI in my current application. I have a case when i need to use ng-class based some field value. i have tried below code but its not working

 $scope.getClass = function (b) {
        console.log(b);
    }
$scope.columns = [
        { "field": "Name", "title": "Name" },
        { "field": "StudentId", "title": "Id" },
        { "field": "Address", "title": "Address", template: "<div ng-class='getclass(#:Address#)'>#:Address#</div>" }
    ]

1 Answer 1

1

All depends on what is your getclass() method returning, the expression must evaluate to true for one of the listed css classes eg. following will add red onto a <p> tag , (you can't return only string name of the class):

<p ng-class=" {red : true}" >Using String Syntax</p>

OR

<span class="base-class" ng-class="myVar='red'">Sample Text</span>

Alternatively you need to use ng-model to swap in between the classes you listed in the ng-class attribute:

<p ng-class="style">Using String Syntax</p>
<input type="text" ng-model="style" placeholder="Type: bold strike red">

OR ng-click to set the variable representing the class.

 <input id="clearbtn" type="button" value="clear" ng-click="myVar=''">
 <br>
 <span class="base-class" ng-class="myVar='my-class'">Sample Text</span>

Look into the documentation.

This is how you pass the kendo template variable into the scope method (plunker):

   $scope.columns = [
                  { "field":"name", "title": "name",  template: '<div ng-class="getClass(\'#:name#\')">#:name#</div>'  },
    ];
Sign up to request clarification or add additional context in comments.

6 Comments

i know how to use data-ng-class my concern is how to bind it with kendo data item. as kendo using #:PropertyName# format.
sorry I misunderstood, I have extended my answer have a look hope it will work for you.
@RaviMittal how is it looking, does it work for you ?
nope. Its not working. but if i pass without single quotes then its working for numeric values not for string
interesting how come its working in the plunker example I have send you, what are you doing differently ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.