Angular radio button reset not working properly

I am using below radio buttons for my form

<input type="radio" class="form-check-input" value="1" [checked]="true" name="keys" [(ngModel)]="lostkey.key">One
 <input type="radio" name="keys" value="2" [(ngModel)]="lostkey.key" class="form-check-input">Both

I set 'One' radio button as a default checked using below code

 ngOnInit() {
this.lostkey.key = '1';
}

this is my reset button. This is working well. all forms reset. but problem is, default radio button also unchecked. therefor i re-assign it after form reset. but it did not work.

reset button (this is working correctly )

<button type="button" class="btn btn-action btn-flat float-right"
(click)="resetForm(reportlostkeyform)">
<i class="fas fa-redo"></i> <span> Reset</span>
</button>

this is reset function

    resetForm(reportlostkeyform: NgForm) {
    reportlostkeyform.reset();
    this.lostkey.key = '1';
  }

how i reassign this radio button value



Read more here: https://stackoverflow.com/questions/67920868/angular-radio-button-reset-not-working-properly

Content Attribution

This content was originally published by Kumara at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: