I've got a form in angular that looks something like this (shortened version with its context removed):
<form [formGroup]="myForm">
Name: <input type="text" formControlName="myName">
<div>
Gender: <input type="text" formControlName="myGender">
</div>
</form>
what I want to accomplish is, by clicking on the gender input field, 2 radio buttons will be displayed and when clicking somewhere outside the gender formblock, the buttons disappear. for that I added a boolean variable to my components ts:
export class MyFormComponent implements OnInit {
genderFocused: boolean = false;
constructor(
) { }
ngOnInit() {
}
}
and tried something like this:
<form [formGroup]="myForm">
Name: <input type="text" formControlName="myName">
<div tabindex="-1" (focusout)="genderFocused = false">
Gender: <input type="text" formControlName="myGender" (focus)="genderFocused = true">
<label>Yes<input type="radio"></label>
<label>No<input type="radio"></label>
</div>
</form>
with that however, as soon as I click on one of the radio buttons, they immediately disappear. I looked around and have not found anything that helped me solve this issue.
I replaced the radio buttons with a text input field, and it behaved the exact same way. as soon as the input field within the div is focused, it disappears, which is not intended