Satish Sharma Satish Sharma - 1 month ago 5
HTML Question

Angular HTML Select option disable and enable

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?

Answer

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}
    ]
  };

This should work for you:

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