首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >angular js : ng-class使用

angular js : ng-class使用
EN

Stack Overflow用户
提问于 2018-07-19 17:40:26
回答 1查看 38关注 0票数 1

我为RestApi获取了一个数据,并且我想创建一个函数来在缺省的==为空或缺省的情况下从json中检索数据。value = false。我使用组件的ng -class更改颜色。

代码语言:javascript
复制
 1:
commandStateTypes:{
defaut interne:null
defaut liaison:{date: "2016-05-30T01:01:04", value: true, name: "defaut liaison", idComponent: 1}}
component:{id:1 ,idInstallation:1,name:"Commande1"}

2:
commandStateTypes:{
defaut interne:null
defaut liaison:{date: "2016-05-30T01:01:04", value: true, name: "defaut liaison", idComponent: 2}}
component:{id:1 ,idInstallation:1, name:"Commande 2"}

 controller : 
     $scope.status = { state: ['OK', 'KO'] }

  Service.GetComponentsHelpers(function (data)
     {

         $scope.componentsHelper = data;


    },
    function (data)
    {

    });


     $scope.GetStateByComponents = function ()
     {

         angular.forEach($scope.componentsHelper, function (componentsState, key)
         {
             angular.forEach($scope.componentsHelper.commandStateTypes, function(value, key){

             });

         });

     }
     chtml:
     <div class="ajoutComponent">
            <div class="motorsVitesse"  ng-class="{ GetStateByComponents() ? 'mDangerV':'mDefaultV'}" alt="{{status.state[1]}}"> {{status.state[1]}}</div>
    </div>
EN

回答 1

Stack Overflow用户

发布于 2018-07-19 18:21:54

在HTML中尝试以下内容:

代码语言:javascript
复制
ng-class="{'mDangerV': GetStateByComponents(), 'mDefaultV': !GetStateByComponents()}"
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51419278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档