How to check for an empty object in an AngularJS view

angularjs, javascript

Solution

You can use: `Object.keys(card).length === 0`

But make sure you use it from a method of the controller as the `Object` is not available in the view, like:

$scope.isObjectEmpty = function(card){
   return Object.keys(card).length === 0;
}

Then you can call the function from the view:

ng-show="!isObjectEmpty(card)"

Problem

In the controller's scope I have something like: ``` $scope.card = {}; ``` In the view I must check if my object is still an empty literal, `{}`, or if it contains some data in some fields. I tried this: ``` ng-show="angular.equals({}, card)" ``` and ``` ng-show="!angular.equals({}, card)" ``` but it didn't work. Are there any better ways? How do you check if an object is empty or if it contains some fields?

Original source

Related problems