JSON in angular frontend

JSON in angular frontend



hi someone can help me to show my json in a frontend angular (like tree or extension)



this is my backend JSON it's a Buildings array grouped by campuses
to make relational mongodb dataBases.


[
{
"_id": "campus4",
"buildings": [

"buildingName": "building7",
"phoneNumber": "00000000000"
,

"buildingName": "building8",
"phoneNumber": "000000000"
,

"buildingName": "building9",
"phoneNumber": "0000000000"

]



my get service :


getBuildings()
return this.http.get(`$this.url/buildings`);



my buildinglist.component.ts :


ngOnInit()
this.fetchBuildings();


fetchBuildings()
this.gesroomService
.getBuildings()
.subscribe((data: Building) =>
this.buildings = data;
console.log('Building data requested...');
console.log(this.buildings);
);





have you something in angular that is requesting these data?
– firegloves
Aug 22 at 13:05





yes i have my service and my "buildinglist.component.ts" where i can fetch the informations. i'll put the in my post. what i want is a component or html to show this
– Saif Ejjilali
Aug 22 at 13:07




1 Answer
1



You can iterate over the first array, accessing _id.
Then you can iterate over buildings list.


_id


buildings



Something like this should work


<div *ngFor="let bList of buildings">

<div>_id: bList._id </div>
<div *ngFor="let b of bList.buildings">
<div>buildingName: b.buildingName </div>
<div>phoneNumber: b.phoneNumber </div>
</div>

</div>





thank you that was helpful !
– Saif Ejjilali
Aug 24 at 8:13






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)