문제

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

도움이 되었습니까?

해결책

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">
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top