如何使用现有的班级名称添加班级名称 [英] How to add class name with the existing class name

查看:114
本文介绍了如何使用现有的班级名称添加班级名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从服务器获取classname作为redbluegreen.我试图用该元素添加该类.但什么也没发生.

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

有人纠正我吗?

这是我的尝试:

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

推荐答案

按原样放置,

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

更有效地

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

这是 DOC

它表示您可以将scope值绑定为

it says you can bind a scope value as,

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

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

为什么要在ng-class中使用{}

如果您要基于如下所示的条件来应用CSS类,

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

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

css类className仅在applyClass设置为true

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

这篇关于如何使用现有的班级名称添加班级名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆