I have a service to get a list of properties, inside that service I am modifying the response using map and returning final array as Observable.
But How I can get that final array as simple JSON from service to my component. This what I have done so far.
SERVICE
getPropertyList(){
let propertyList$ : Observable<any> = this._http.get('http://localhost:3000/...');
return propertyList$.pipe(
map(data => {
// do your transformations
let listArray: Array<any> = data.response.dataset;
listArray.forEach(list => {
list.name = 'jhon deo';
})
return listArray;
})
)
}
Component
this._service.getPropertyList()
.subscribe({
next: (result) => {
console.log(result);
},
error: (err) => {
console.log(err);
}
})
I am trying to achieve it like this from Component -
getData(){
const listData: Array<any> = this._service.getPropertyList();
}