我获取RestApi的数据,我想创建一个函数以从json检索数据 如果defautl == null或默认值。值= false。我使用组件的ng -class更改颜色。
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>
答案 0 :(得分:-1)
尝试使用HTML:
ng-class="{'mDangerV': GetStateByComponents(), 'mDefaultV': !GetStateByComponents()}"