有没有办法让ng-show适用于0长度的字符串''?
angular.module('app', []).controller('app', appController);
function appController($scope) {
$scope.zero = '';
$scope.string = 'string';
$scope.n = null;
}

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="app">
<div ng-show="zero">MAKE THIS APPEAR</div>
<div ng-show="string">This appears, as usual</div>
<div ng-show="n">This should not appear, as usual</div>
</div>
&#13;
答案 0 :(得分:4)
您可以这样做:
ng-show="zero.length >= 0"
如果您只想要零长度字符串,可以将其更改为:
ng-show="zero.length === 0"