How to add class name with the existing class name

时间:2015-06-25 09:59:33

标签: angularjs

I am getting classname from server as red,blue or green. i trying to add that class with the element. but nothing happening.

any one correct me please?

here is my try:

    <span class="proStatus" ng-class="{activeApp.status}"> //class not adds
      {{activeApp.status}} //i am getting `blue` here.
   </span>

1 个答案:

答案 0 :(得分:5)

just put as,

<span class="proStatus {{activeApp.status}}"> ...

or MORE efficiently

<span class="proStatus" ng-class="activeApp.status"> ....

here is the DOC

it says you can bind a scope value as,

$scope.className = 'this-is-class-name';

<span class="proStatus" ng-class="className">

Why use { } in ng-class

if you want to apply a css class based on some condition like below,

<span class="proStatus" ng-class="{ 'className' : applyClass }">

css class className will apply to the span only when applyClass is sets to true