Angularjs显示验证如果一个或多个值是数组中的空 [英] Angularjs show validation if one or more value is empty in the array
本文介绍了Angularjs显示验证如果一个或多个值是数组中的空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里有一个angularjs 样品我曾经 NG-重复
为
I have an angularjs sample here where I used ng-repeat
as
<div ng-app="Test">
<div ng-controller="TestController">
<div ng-repeat="str in myData">{{str.id}}. {{str.string}}</div>
<br/> <span ng-if="myData.length > 1" style="color:red;">One or more string is empty</span>
</div>
</div>
从阵列绘制列表。我想说明的验证,如果有数组中的一个或多个值PF字符串为空。我怎样才能实现呢?
to draw the list from an array. I want to show an validation if there are one or more value pf string in the array is empty. How can I achieve it?
推荐答案
您可以循环在你的控制器的阵列,并增加可变说计数
当你的字符串是空的。在此基础上计数
您可以管理您的UI元素的值。
You can iterate the array in your controller and increment a variable say count
when your string is empty. Based on that count
value you can manage your UI elements.
例如:
在你的控制器:
For Example: In you controller:
$scope.count = 0;
for(var i = 0; i < $scope.myData.length; i++){
if($scope.myData[i].string === ""){
$scope.count ++;
}
}
在你的HTML:
<div ng-repeat="str in myData">{{str.id}}. {{str.string}}</div>
<br/>
<span ng-if="count >= 1" style="color:red;">One or more string is empty</span>
</div>
希望它帮助。
这篇关于Angularjs显示验证如果一个或多个值是数组中的空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文