Question

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

Was it helpful?

Solution

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">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top