I am trying to display a text-field based on the selected value of a radio button group.
If the user selects "Yes", then I want to display the text-field. If the user selects "No", then I don't want to display this text-field.
Below is my HTML:
<radio-button-wrapper
[(ngModel)]="damageReported"
name="rdoDamageReported">
<radio
id="preselection_damageReported_01"
heading="Yes"
name="validationDamageReported"
value="Yes">
</radio>
<radio
id="preselection_damageReported_02"
heading="No"
name="validationDamageReported"
value="No"
(click)="clearSecondCompanyFields()">
</radio>
</radio-button-wrapper>
<div class="form-group" *ngIf="damageReported.value === 'Yes'">
<label
for="txtOtherCompanyName"
class="control-label">
Please state the name of the other insurance company:
</label>
<input
class="form-control"
id="txtOtherCompanyName"
name="txtOtherCompanyName"
[(ngModel)]="otherCompanyName"
type="text"/>
</div>
In my .TS file, I have this uninitialized variable:
public damageReported;
The error message I am getting in the console is:
TypeError: _co.damageReported is undefined
I know this is because I haven't initialized damageReported in my .TS file.
But if I initialize it like so: damageReported = ''
;
I get this compile error when I try to use the radio button value at a later stage in the code:
this.postData(
this.damageReported.value
)
postData(
damageReported: string
)
Property 'value' does not exist on type 'string'.ts(2339)
Can someone please show me how I can initialize the variable while also being able to use the .value property? Thanks a lot!