I am currently facing an issue with implementing a custom radio button element in Angular.
Below is the code snippet for the markup I want to make functional within the parent component:
<form>
<my-radio [(ngModel)]="radioBoundProperty" value="1" name="myCustomRadioButton">Btn 1</my-radio><br>
<my-radio [(ngModel)]="radioBoundProperty" value="2" name="myCustomRadioButton">Btn 1</my-radio><br>
</form>
<p>
The current value of radioBoundProperty is:
</p>
<pre>{{radioBoundProperty|json}}</pre>
So far, I have created a custom radio component by utilizing ControlValueAccessor
.
The issue arises when attempting to retrieve the selected value from my-radio
component back to the parent component using ngModel for two-way data binding.
Even if I modify the value of radioBoundProperty
, it overrides the values of the `value` attribute for both my-radio elements.
Click here for an updated stackblitz that demonstrates a successful example:
stackblitz showcases the functioning example with accompanying code