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
应!TRUE
的table
是反正显示
难道我做错了什么 ?
该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)