角HTML选择选项禁用和启用 [英] Angular HTML Select option disable and enable

查看:139
本文介绍了角HTML选择选项禁用和启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML选择选项

I have a html select option

<select>
    <option ng-repeat="field in filter.fields" value="{{field.id}}">{{field.name}}</option>
</select>

而我从纳克重复迭代,我想禁用一个可选择的申请的基础上选择像

which I am iterating from ng-repeat , I want to disable option on basis of a filed selectable like

<select>
    <option ng-repeat="field in filter.fields" {field.selectable==true?enable:disable} value="{{field.id}}">{{field.name}}</option>
 </select>

我如何与角度做到这一点?

How can I achieve this with angular?

推荐答案

假设你有一个这样的结构:

Assuming you have a structure like this:

  $scope.filter = {
    fields: [
      {id: 1, name: "a", selectable: false},
      {id: 2, name: "asdf", selectable: true},
      {id: 3, name: "qwet", selectable: false},
      {id: 4, name: "qnjew", selectable: true},
      {id: 5, name: "asdjf", selectable: false}
    ]
  };

这应该为你工作:

  <select>
    <option ng-repeat="field in filter.fields" ng-disabled="field.selectable" value="{{field.id}}">{{field.name}}</option>
  </select>

这篇关于角HTML选择选项禁用和启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆