【问题标题】:How to set multiple classes in my case?在我的情况下如何设置多个类?
【发布时间】:2014-12-12 06:43:14
【问题描述】:

我正在尝试在我的应用程序的 ng-class 中设置多个条件。我有类似的东西

 <div id='wrapper' ng-class="{red: !isBlue(), 
                              highlight ? 'yellow' : 'black'}" 
 ng-show="test">Test</div>

JS

  $scope.highlight = false;

我的问题是在 ng-class 条件下出现语法错误。

Syntax Error: Token ';' is unexpected, expecting [}] at column 48...

我不知道如何解决它。任何人都可以帮助我吗?谢谢!

【问题讨论】:

    标签: html css angularjs class


    【解决方案1】:

    你可以像这样使用多个类,你需要为highlight!highlight添加单独的类

    <div id='wrapper' 
                    ng-class="{'red': !isBlue(), 'yellow':highlight ,'black':!highlight }"
                    ng-show="test">
           Test
    </div>
    

    这是一个演示Plunker (ng-class)


    你有另一种选择 ng-style 用这个你可以实现你尝试过的东西,

    <div id='wrapper' ng-style="{color: (highlight ? 'yellow' : 'green')}" ng-show="test">Test</div>
    

    这里是演示Plunker (ng-style)

    【讨论】:

      猜你喜欢
      • 2015-09-20
      • 2018-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-16
      • 1970-01-01
      相关资源
      最近更新 更多