0

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?

1 Answer 1

2
<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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.