1

I'm having trouble grasping that when item.dynamicClass = 'article' why

<div class="type" ng-class="{{ item.dynamicClass }}">

doesn't return a div like:

<div class="type article">

but instead returns:

<div class="type" ng-class="article">


The only way I've been able to get this work is by doing

<div class="type" ng-class="itemClass(item.dynamicClass)">

// Controller
$scope.itemClass = function(type) {
  return type;
};

I would like a solution which doesn't involve the controller

0

1 Answer 1

3

I don't think you need the binding braces. What is passed to ng-class is an expression that evaluates to a result, not something to bind (fiddle):

<div class="type" ng-class="item.dynamicClass">
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I thought I tried that but I guess not. Also doing class="type {{ item.dynamicClass }}" didn't feel right either.

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.