Level 7
I have sorted this by following this: https://www.positronx.io/angular-7-httpclient-http-service/
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Both my Service file and my component return the same array of 12 items, great but surely, I should just be using one or the other?!
here is my Service file:
getAllFinds(): Observable<any> {
const currentUser = localStorage.getItem('currentUser');
const token = JSON.parse(currentUser).token;
const httpHeaders = {
headers: new HttpHeaders({
'content-type': 'application/json',
'Authorization': 'Bearer '+token
})
}
return this.http.get<any>("https://lookwhatfound.me/api/allartworks", httpHeaders)
.pipe(map(finds => {
console.log('finds: ',finds)
return finds;
}))
}
and here is my component:
ngOnInit(): void {
this.loadAllFinds();
this.findsService.getAllFinds();
}
loadAllFinds() {
this.findsService.getAllFinds()
.pipe(takeUntil(this.destroy$))
.subscribe(Finds => {
console.log('Finds: ', Finds)
});
}
I have sorted this by following this: https://www.positronx.io/angular-7-httpclient-http-service/
Please or to participate in this conversation.