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?
While the ng-disabled attribute will technically work, you are likely to encounter bugs when using ng-repeat on options. This is a well known issue and is exactly the reason that the angular team created ng-options. There is not yet an angular implementation for using ng-options and ng-disabled together, but Alec LaLonde created this custom directive that you can add in and use. See the issue forum here: https://github.com/angular/angular.js/issues/638 and the jsfiddle from that post.
Assuming you have a structure like this:
This should work for you:
This is actually a fairly old question. In the later version of Angular (angular 1.4+) you have the ngOptions directive. Here is the link:-
https://docs.angularjs.org/api/ng/directive/ngOptions
There is now a syntax for handling this case:-
I thought I would put this in in case someone else visits this page.