0

How can I assign flag true or false while clicking on input field as: In my .ts file:

 one:boolean=false;
 two:boolean=false;

In .html File

<div class="container">
   <label>Yes
      <input type="radio" id="one">
   </label>
</div>
<div class="container">
   <label> No
      <input type="radio" id="one">
   </label>
</div>
thatguy
  • 21,059
  • 6
  • 30
  • 40
naman
  • 51
  • 4
  • Does this answer your question? [How can I check whether a radio button is selected with JavaScript?](https://stackoverflow.com/questions/1423777/how-can-i-check-whether-a-radio-button-is-selected-with-javascript) – JayCodist Aug 10 '20 at 07:15

2 Answers2

1

Bind your radio button with [(ngModel)] will solve your problem.

Try this.

<div class="container">
  <label>Yes
    <input type="radio" id="one" name="one" [(ngModel)]="one" value="true">
  </label>
</div>
<div class="container">
  <label> No
    <input type="radio" id="one" name="one" [(ngModel)]="one" value="false">
  </label>
</div>
Vivek Jain
  • 2,730
  • 6
  • 12
  • 27
0

Try this

<p>
   <input type="radio" value="one" name="gender" [(ngModel)]="result" (ngModelChange)="setValues()" > One
   <input type="radio" value="two" name="gender" [(ngModel)]="result"  (ngModelChange)="setValues()" > Two
</p>

And in ts

one =true;
 two=false;
 result;

 setValues(){
  this.one =this.result === 'one' ? true :false;
  this.two =this.result === 'two' ? true :false;
 }
Jobelle
  • 2,717
  • 1
  • 15
  • 26