I am trying to display my ngForm data in the HTML file using the Json pipe in my Angular 9 project.
The result I wish to get from the below code should be
{"name":"name input","contactNumber":"07123" }
I tried this:
{{ form.value | json }}
and I have also tried
{{ form| json }}
to display all angular ngForm data, but still no luck.
On my HTML nothing is being shown, but if I do {{form}}, I get [object object].
Note: FORMS MODULE is imported.
The error I am getting on the console:
VM21 vendor.js:15247 ERROR TypeError: Converting circular structure to JSON
--> starting at object with constructor 'TView'
| property 'blueprint' -> object with constructor 'LViewBlueprint'
--- index 1 closes the circle
at JSON.stringify (<anonymous>)
at JsonPipe.transform (VM21 vendor.js:5866)
at Module.ɵɵpipeBind1 (VM21 vendor.js:43023)
at BookingFormComponent_Template (VM20 main.js:579)
at executeTemplate (VM21 vendor.js:20324)
at refreshView (VM21 vendor.js:20171)
at refreshComponent (VM21 vendor.js:21609)
at refreshChildComponents (VM21 vendor.js:19900)
at refreshView (VM21 vendor.js:20223)
at refreshComponent (VM21 vendor.js:21609)
HTML code:
<form #form="ngForm" class="box p-4 mx-lg-0 mx-1 mb-3 rounded font-weight-bold">
<div class="form-group">
<label for="clientName">Name</label>
<input id="clientName" placeholder="Enter your name!" ngModel/>
</div>
<div class="form-group">
<label for="contactNumber">Contact Number</label>
<input id="contactNumber" placeholder="Enter your contact number!" ngModel/>
</div>
<h3>{{ form | json }}</h3>
<h3>{{ form.value | json }}</h3>