I've the basic idea about how observable works, I'm able to get the data by calling subscribe method and render the data in my template. But I could not enumerate the data returned by the observable in my component. I would like to process my data at component level before sending them to my template.
I've tried this so far:
My Service:
getCountries(): Observable<IUser> {
return this.http.get<IUser>('https://jsonplaceholder.typicode.com/posts');
}
My ngInit method in the component:
ngOnInit() {
this.countryService.getCountries().subscribe((users => {
this.userJson = users;
}));
console.log(this.userJson); // Showing undefined
//giving exception while calling length property
for (var i = 0; i < this.userJson.length; i++) {
}
}
Not sure how to approach this?