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);
);
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.
have you something in angular that is requesting these data?
– firegloves
Aug 22 at 13:05