当从select输入中选择一个值时,需要设置输入禁用

时间:2017-01-06 13:13:49

标签: angularjs node.js

我需要设置这三个输入禁用

<input type="text" class="col-md-6" ng-model="a.one" name=""/>
<input type="number" class="col-md-6" ng-model="a.two" name="" ng-disabled="cm" required="required"/>
<div class='input-group date' id='date'>
                          <input type='text' ng-model="a.three" name="toDate" class="form-control" style="height:30px;" ng-disabled="cm" />
                          <span class="input-group-addon">
                           <span class="glyphicon glyphicon-calendar"></span>
                          </span>
                        </div>

当我从下面的输入中选择一个值时:

<select class="col-md-6 dropdown-height" ng-model="a.select" name="" ng-options="ms for ms in section" required="required"></select>

select输入中的选项值来自api

scope.mapping = function () {
          ApiServices.getAllValues().then(
                function (response) {
                   scope.map= response.data;
                 });
             };

我该怎么办?

2 个答案:

答案 0 :(得分:0)

 <input ng-disabled="a.select==='your_value'">

对三个输入执行此操作。

答案 1 :(得分:0)

你可以采取两种方式。
1.将ng-disabled="a.select"应用于您要禁用的元素 2.如果您想申请更多输入字段,这会好得多 将html包装在fieldset中并应用ng-disabled。以下是工作代码

&#13;
&#13;
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope){
  $scope.cm = true;
  $scope.enable= function() {
    $scope.cm = !$scope.cm;
  }
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="myApp" ng-controller="myCtrl">
<fieldset ng-disabled="cm">
<input type="text" class="col-md-6" ng-model="a.one" name=""/>
<input type="number" class="col-md-6" ng-model="a.two" name="" required="required"/>
<div class='input-group date' id='date'>
                          <input type='text' ng-model="a.three" name="toDate" class="form-control" style="height:30px;" />
                          <span class="input-group-addon">
                           <span class="glyphicon glyphicon-calendar"></span>
                          </span>
                        </div>
</fieldset>
  <button ng-click="enable()">enable fields</button>
  </div>
&#13;
&#13;
&#13;