Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 468
Satish Sharma Avatar asked Sep 10 '13 15:09

Satish Sharma


People also ask

Can you disable a select HTML?

The disabled attribute for <select> element in HTML is used to specify that the select element is disabled. A disabled drop-down list is un-clickable and unusable. It is a boolean attribute.

How do I turn off Ng select options?

In your <ng-option> , put a [disabled] attribute with some conditional in it.

How do I disable mat select?

Disabling the select or individual options It is possible to disable the entire select or individual options in the select by using the disabled property on the <select> or <mat-select> and the <option> or <mat-option> elements respectively.

How do you enable disable a dropdown based on value in another dropdown in angular?

get('yourPath'). disable({onlySelf: true}); If not, you can also just use the [disabled]="isFieldDisabled" property on the <select> property. If you use a FormGroup with your DropDownField but choose to disable the DropDownField via [disabled]="..." , then you will get much yellow text in your console.


1 Answers

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>
like image 154
Kasper Lewau Avatar answered Oct 14 '22 21:10

Kasper Lewau