且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在AngularJS视图中检查空对象

更新时间:2023-11-29 10:57:34

您可以使用: 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)"