问题描述:
<div ng-if="Object.getOwnPropertyNames(auth).length > 1"></div>
在ng-if中写上条件Object.getOwnPropertyNames(auth).length > 1,div不显示。在浏览器控制台输入Object.getOwnPropertyNames($scope.auth).length > 1打印的值为true。
在页面写上:
<span ng-bind="Object.getOwnPropertyNames(auth).length > 1"></span>
显示为false。
解决方法:
将html代码改为:
<div ng-if="getObjPropertyLength(auth).length > 1"></div>
在controller中添加:
$rootScope.getObjPropertyLength = Object.getOwnPropertyNames;
错误原因:
Object.getOwnPropertyNames函数是javascript函数,在控制台可以正常调用它。
但是由于Object.getOwnPropertyNames不在$scope域上,所以在html代码中不能调用