使ng-show适用于0长度字符串""

时间:2014-11-02 15:11:34

标签: angularjs-ng-show

有没有办法让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;
&#13;
&#13;

1 个答案:

答案 0 :(得分:4)

您可以这样做:

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

如果您只想要零长度字符串,可以将其更改为:

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

这是一个傻瓜:http://plnkr.co/K7DyPukQHcDyLAUw4Dua