In my Angular2 project, I am working on retrieving JSON data to get all the rooms
and store them in an array.
Below is the code for the RoomlistService that helps me fetch the correct JSON file:
@Injectable()
export class RoomlistService {
constructor(private http: Http) { }
getRooms(room) {
console.log('get all rooms: ');
return this.http.get('../../assets/rooms/' + room + '.json')
.map(response => response.json());
}
}
Here is the Component that utilizes the service to retrieve the data:
ngOnInit() {
this.routeUrl.paramMap.subscribe( (param) => {
this.buildingID = param.get('id');
this.service.getRooms(this.buildingID).subscribe(data => {
console.log(data);
});
});
}
As of now, everything is functioning correctly, and when using console.log
, I can see the object being returned.
https://i.sstatic.net/WYii8.png
My goal is to extract all rName
values from the object and store them in an array. However, my attempts have been unsuccessful so far. Any assistance in achieving this would be greatly appreciated.