0

有没有办法让 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>

4

1 回答 1

4

你可以这样做:

ng-show="zero.length >= 0"

如果您只希望它用于零长度字符串,您可以将其更改为:

ng-show="zero.length === 0"

这是一个 plunkr:http ://plnkr.co/K7DyPukQHcDyLAUw4Dua

于 2014-11-02T15:17:40.487 回答