My service retrieves JSON data from the backend:
constructor(private http: Http) { };
getUsers(): Observable<any> {
return this.http.get('http://127.0.0.1:8000/app_todo2/users_list');
};
In the component, this data is processed:
ngOnInit() {
this.retrieveUserData();
}
private retrieveUserData(): void {
this.userDataService.getUsers().subscribe(
data => {
this.processedUserData = JSON.parse(data.json());
console.log(this.processedUserData);
})
};
However, I would like to process this data in the service instead. And then receive the clean data in the component:
private retrieveUserData(): void {
this.userDataService.getUsers().subscribe(
data => {
this.processedUserData = data;
console.log(this.processedUserData);
})
};
Could someone please assist me with this?