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?
return Object.keys(obj).length === 0 ; This is typically the easiest way to determine if an object is empty.
We can also explicitly check if the array is empty or not. if (arr. length === 0) { console. log("Array is empty!") }
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)" 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With