Angular: How to print / toString() Object, Array, formGroup values
1 min readOct 12, 2020
JSON.stringify converts almost all kind of typescript objects, arrays, formGroups into JSON formatted string.
JSON.stringify(object/array/formGoupValue)
An alternative to JSON.stringify is string interpolation notation. Ex.`{$value}` or `{$object.property}`
Example using both JSON.stringify and string interpolation
this.formGroup.valueChanges.subscribe(val => {console.log(‘Changed: {$val.name} : {$val.password} ’);console.log('Changed: ' + JSON.stringify(val));});
We can do similar from Angular template using jsonPipe to quickly show object / array / formGroup value in JSON format in any HTML page
<b>Current Values:</b>{{profileForm.value | json}}First Name value: {{profileForm.get(‘firstName’).value | json}}