[英]ANGULAR: Turn off inputs in a loop
I have a loop (ng-repeat) that generates several inputs and another loop that generates other inputs. 我有一个生成多个输入的循环(ng-repeat),另一个生成其他输入的循环。 My question is: I need to enable or disable the inputs of the second loop in function if the inputs of the first loop have data or not.
我的问题是:如果第一个循环的输入是否有数据,我需要启用或禁用第二个循环的输入。 Here is my code:
这是我的代码:
<md-input-container class="md-block" ng-repeat="rec in recursos">
<label>{{rec.title}}</label>
<input type="text" name="rec" ng-model="rec.desc" ng-required="true">
<div ng-messages="myForm2.rec.$error">
<div ng-message="required">Campo obligatorio</div>
</div>
</md-input-container>
<md-input-container class="md-block" ng-repeat="prep_par in presupuestoPartidas">
<label>{{prep_par.title}}</label>
<input type="number" name="prep_par" ng-model="prep_par.importe" min="0" ng-required="true" >
<div ng-messages="myForm2.prep_par.$error">
<div ng-message="required">Campo obligatorio</div>
</div>
</md-input-container>
Assuming that the first loop uses the array $scope.firstLoop
, you just need to set the ng-disabled
of the inputs of the second loop to the $scope.firstLoop.length
variable. 假设第一个循环使用数组
$scope.firstLoop
,则只需将第二个循环的输入的ng-disabled
设置为$scope.firstLoop.length
变量。 If the array is empty, then the inputs of the second loop are disabled. 如果数组为空,则禁用第二个循环的输入。
<md-input-container class="md-block" ng-repeat="rec in recursos">
<label>{{rec.title}}</label>
<input type="text" name="rec" ng-model="rec.desc" ng-required="true" ng-disabled="firstLoop.length">
<div ng-messages="myForm2.rec.$error">
<div ng-message="required">Campo obligatorio</div>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.