Shashika Virajh
Shashika Virajh

Reputation: 9487

Disabling and enabling select using angular

I want to disable and enable a select, using angular based on a condition.

  <select [disabled]="!isContinentSelected" class="form-control" formControlName="country">
      <option value="">Select Your Country</option>
      <option *ngFor="let country of countries" value="{{country.id}}">{{country.name}}</option>
 </select>

isContinentSelected returns true or false. But the is always enable even the condition is false. Im using Angular 5. How can I achieve this?

Upvotes: 0

Views: 1186

Answers (1)

Lead Developer
Lead Developer

Reputation: 1169

<select [attr.disabled]="isContinentSelected ? '': null" class="form-control" formControlName="country">
      <option value="">Select Your Country</option>
      <option *ngFor="let country of countries" value="{{country.id}}">{{country.name}}</option>
 </select>

Please try with this code. This works in my case.

Upvotes: 2

Related Questions