Here is an example of a scenario where I have created a service to retrieve a list of properties. Within this service, I am utilizing the map function to manipulate the response and then returning the final array as an Observable.
My question is: How can I easily obtain that final array in JSON format from the service and pass it to my component? Below is what I have accomplished thus far:
SERVICE
getPropertyList(){
let propertyList$ : Observable<any> = this._http.get('http://localhost:3000/...');
return propertyList$.pipe(
map(data => {
// perform necessary transformations
let listArray: Array<any> = data.response.dataset;
listArray.forEach(list => {
list.name = 'John Doe';
})
return listArray;
})
)
}
COMPONENT
this._service.getPropertyList()
.subscribe({
next: (result) => {
console.log(result);
},
error: (err) => {
console.log(err);
}
})
In my component, I am attempting to achieve the desired result like so -
getData(){
const listData: Array<any> = this._service.getPropertyList();
}