Javascript 在AngularJS表单中禁用select标记内的选项

Javascript 在AngularJS表单中禁用select标记内的选项,javascript,html,angularjs,frontend,Javascript,Html,Angularjs,Frontend,我有一个表格,有两个选项。我想实现的是,如果在第一次选择中选择了“Any”选项,则在另一次选择中禁用其中一个选项 因此,在这里,如果选择了“Any”(vm.scriptTypes的一部分,vm是控制器): <select name="scriptType" id="scriptType" class="form-control" required ng-model="vm.rule.scriptType" ng-options="option.name as

我有一个表格,有两个选项。我想实现的是,如果在第一次选择中选择了“Any”选项,则在另一次选择中禁用其中一个选项

因此,在这里,如果选择了“Any”(vm.scriptTypes的一部分,vm是控制器):

<select name="scriptType" id="scriptType" class="form-control" required
        ng-model="vm.rule.scriptType"
        ng-options="option.name as option.name for option in vm.scriptTypes">
</select>

从vm.actions(ng选项)中禁用“组合禁止”(“组合禁止”是vm.actions的一部分,它是一个对象,具有“类型”和“命令”键)



提前感谢您提供的任何帮助。

您可以在ngOptions中使用
禁用when
参数


为什么不试试select中的选项标签呢? 例如:


{{option.type+''+option.command}}
如果不起作用,请告诉我。
但是我没有测试它

太好了!非常感谢。这不起作用,我不知道为什么\
<select name="action" id="action" class="form-control" required
        ng-model="vm.rule.action"
        ng-change="vm.rule.action "
        ng-options="(option.type + ' ' + option.command) as (option.type + ' ' + option.command) for option in vm.actions">
</select>
<div ng-app="TestApp" ng-controller="TestController">
  <select name="scriptType" id="scriptType" class="form-control" required
          ng-model="rule.scriptType"
          ng-options="option.name as option.name for option in scriptTypes">
  </select>
  <select name="action" id="action" class="form-control" required
        ng-model="rule.action"
        ng-change="rule.action "
        ng-options="(option.type + ' ' + option.command) as (option.type + ' ' + option.command) disable when (rule.scriptType == 'Any' && option.type == 'Combination ban') for option in actions">
</select>
</div>
var app = angular.module('TestApp', []);

app.controller('TestController', function($scope) {
  $scope.scriptTypes = [{
    name: 'Any'
  },
  {
    name: 'ron'
  },
  {
    name: 'ron2'    
  }];
  $scope.actions = [{
    type: 'type1',
    command: 'cmd1',
  },
  {
    type: 'type2',
    command: 'cmd2',
  },
  {
    type: 'Combination ban',
    command: 'Combination ban',
  }];
});
<select name="action" id="action" class="form-control" required
    ng-model="vm.rule.action"
    ng-change="vm.rule.action "
    ng-options="(option.type + ' ' + option.command) as (option.type + ' ' + option.command) for option in vm.actions">
    <option value="{{option.type + ' ' + option.command}}" ng-disabled="option.type == 'Combination ban' && vm.rule.scriptType == 'Any'">{{option.type + ' ' + option.command}}</option>
</select>