【发布时间】:2014-09-26 23:06:56
【问题描述】:
我有一个文本区域,我在其上应用了 angular 的最大长度指令:
<textarea placeholder="Quote text here" ng-model="quote.text" ng-maxlength="400" name="text"></textarea>
现在我还通过使用角度 ng-show 和 ng-hide 指令来显示字数:
<div class="row word-count">
<h5>Word count :</h5>
<h5 ng-show="quote.text.length > 0">{{quote.text.length}}</h5>
<h5 ng-hide="quote.text.length > 0" class="ng-hide">0</h5>
</div>
问题在于,一旦字数超过最大长度指令,ng-show 和 ng-hide 就会自动触发为反向。有没有办法阻止它?
【问题讨论】:
-
您在处理负长度吗?为什么有 ng-show 和 ng-hide?只需打印出quote.text.length。没有单词的时候会是0,对吧?您只需要将默认文本清空即可。
标签: angularjs angularjs-directive