2

I have a table where I am repeating over an array of objects. Within the object, there is a nested object, like so:

[
    {"Object1": 
         {"Sub_obj" : {}
         }
     },

    {"Object2": 
         {"Sub_obj" : 
               {"Name" : "Jane"}
         }
     }
]

I want to ng-hide the table row where "Sub_obj" is empty. How can I achieve this? I tried ng-hide=!Sub_obj, but that doesn't work.

Nishant Roy
  • 1,043
  • 4
  • 16
  • 35

2 Answers2

3

Make a simple function that checks the length of the keys in object:

$scope.isEmptyObject(obj){
  return !angular.isObject(obj) || !Object.keys(obj).length
}

view

ng-hide="isEmptyObject(item.Sub_obj)"
charlietfl
  • 170,828
  • 13
  • 121
  • 150
0

ng-hide="Sub_obj.Name == null ;

OR ng-hide="Sub_obj.Name == ""