Morlas
Morlas

Reputation: 121

Angular HttpClient get method subscribe Cannot read property 'length' of undefined

I'm trying to determine whether file exists, by using httpclient's method get.

Then based on the outcome if file exists or not call one method with different argument.

 public faviconLogic(iconName: string): void {
    this.getFile(`assets/favicon/${iconName}/favicon.ico`)
    .subscribe(
      () => this.setFavicon(iconName),
      () => this.setFavicon('default')
    );
  }

  private getFile(filename: string): Observable<Blob> {
    return this.http.get(filename, { responseType: 'blob' });
  }

When entering method faviconlogic I get error

TypeError: Cannot read property 'length' of undefined
    at t.applyUpdate

I tried adding headers - nothing. Calling method getFile itself works without problem lays with subscription to Observable returned on get. What am I doing wrong?

Upvotes: 0

Views: 386

Answers (1)

Morlas
Morlas

Reputation: 121

Ok, the problem was with authorization token in Http Headers.

Upvotes: 1

Related Questions