我使用ng-repeat生成一些行,我根据特定条件显示每行的错误。我的代码工作得很好。现在,如果我有任何错误,我想禁用一个超出ng-repeat范围的按钮。我怎么能这样做?
html代码
<div ng-repeat="item in itemList">
<input type="text" ng-model="item.name" />
<input type="text" ng-model="item.phone" />
<div ng-if="validateRow(item)">Here is my error</div>
</div>
<button ng-disabled="I want to disabl this if there is some error for the above ng-repeat">Click </button>
js code
$scope.validateRow = function(item) {
return true or false based on item values
}
答案 0 :(得分:0)
这个例子应该足够了
<div ng-repeat="item in itemList">
<input type="text" ng-model="item.name" />
<input type="text" ng-model="item.phone" />
<div ng-show="validateRow(item)">Here is my error</div>
</div>
<button ng-disabled="isDisabled">Click </button>
function MyCtrl($scope) {
$scope.itemList = [{"name": "", "phone": "123"},{"name": "", "phone": "456"},{"name": "", "phone": "789"}];
$scope.disable= false;
$scope.validateRow = function(item) {
$scope.disable= false;
for(var c =0; c < $scope.itemList.length; c++){
if($scope.itemList[c].name != "abc"){
$scope.disable = true;
break;
}
}
return item.name != 'abc';
}
}
使用链接工作进行更新
答案 1 :(得分:0)
在视图中
<button ng-disabled="disable">Click </button>
在控制器中,
$scope.disable= false;
$scope.validateRow = function(item) {
if(true based on item values) // if your going to return true
$scope.disable= true;
}
return true or false based on item values
}