简体   繁体   中英

ng-repeat hide rows with empty object

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.

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)"

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM