AngularJS angular.equals在ng-show上的工作方式不同

sti*_*ife 3 object-comparison angularjs ng-show

我的控制器中有这些线

$scope.VLANEnabledServers = {};
$scope.myEmpty = {};
console.log(angular.equals($scope.myEmpty, $scope.VLANEnabledServers));
Run Code Online (Sandbox Code Playgroud)

ng-show在模板中

<table ng-show="!angular.equals(myEmpty, VLANEnabledServers)" ng-cloak class="table table-striped table-bordered ng-hide">
Run Code Online (Sandbox Code Playgroud)

angular.equals控制器中的功能打印TRUE正确.但在视图中,在条件ng-show!TRUEtable是反正显示

难道我做错了什么 ?

Ed *_*ffe 7

ngShow指令将角度表达式作为属性.

角度表达在它可以包含的内容中是有限的,虽然它有时看起来像javascript,但实际上并非如此.有关什么是有效角度表达式的详细信息,请参阅链接页面.

您最有可能想要做的是在作用域上创建一个函数来为您进行比较,然后从表达式中调用该函数:

$scope.isEmptyObject = function (item){
  return angular.equals( {} , item );
}
Run Code Online (Sandbox Code Playgroud)

附:

<table ng-show="!isEmptyObject(VLANEnabledServers)">
Run Code Online (Sandbox Code Playgroud)