Hi All,
In this short tutorial we will cover an angular 9/8/7 json pipe format. We will look at example of how to use json pipe in angular. I’m going to show you about angular jsonPipe. it's simple example of angular json pipe example. Let's see bellow example angular json pipe example.
Json pipe help to debug your object or object array because you can not print direct object in view file. so you can display it in json array see. json pipe will use for developing mostly but also widely. here i will show you how to use json pipe in angular 6, angular 7, angular 8 and angular 9.
I am not going to explain more and more description but i will simply give you syntax and some small examples so you can easily use it in your application.
Syntax:
{{ value_expression | json }}
Json Pipe with Object
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<div>
<p>{{ myObject }}</p>
<p>{{ myObject | json }}</p>
</div>`,
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
myObject = {
id: 1,
name: "Hardik"
};
}
Output
[object Object]
{ "id": 1, "name": "Hardik" }
Json Pipe with Object Array
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<div>
<p>{{ myArrayObject }}</p>
<p>{{ myArrayObject | json }}</p>
</div>`,
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
myArrayObject = [
{
id: 1,
name: "Hardik",
roles: [1, 2, 3]
},
{
id: 1,
name: "Harsukh",
roles: [1, 2, 4, 5]
}
];
}
Output
[object Object],[object Object]
[ { "id": 1, "name": "Hardik", "roles": [ 1, 2, 3 ] }, { "id": 1, "name": "Harsukh", "roles": [ 1, 2, 4, 5 ] } ]
I hope it can help you...
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example