Angular: How to print / toString() Object, Array, formGroup values

Monir Khan
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}}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Monir Khan
Monir Khan

Written by Monir Khan

System developer, Swedish board of agriculture

No responses yet

Write a response