10

I have a radio group which uses the same form control for each option. Is it possible to disable just the red radio button? I know you can set the disabled flag on the color form control but this will disabled all radio buttons.

<fieldset [formGroup]="colorForm">
    <legend>
      Choose color
    </legend>

<div class="radio">
  <label>
    <input type="radio" value="red" formControlName="color">
    Red
  </label>
</div>

<div class="radio">
  <label>
    <input type="radio" value="green" formControlName="color">
    Green
  </label>
</div>

<div class="radio">
  <label>
    <input type="radio" value="blue" formControlName="color">
    Blue
  </label>
</div>

1 Answer 1

19

try this out

 <input type="radio" [attr.disabled]="propertyName === false || null"" 
  value="red" formControlName="color">

propertyName i.e. value comes from components.ts file

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

1 Comment

Thanks Pranay Rana. That is basically the same thing I just came up with. It looks like it is working.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.