Summer Sale! All accounts are 50% off this week.

boyjarv's avatar

Angular frontend API requests

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)
    });
  }
0 likes
1 reply

Please or to participate in this conversation.