Requesting non-JSON data with HttpClientModule in Angular

getTextFile(filename: string) {
  // The Observable returned by get() is of type Observable<string>
  // because a text response was specified.
  // There's no need to pass a <string> type parameter to get().
  return this.http.get(filename, {responseType: 'text'})
    .pipe(
      tap( // Log the result or error
        data => this.log(filename, data),
        error => this.logError(filename, error)
      )
    );
}

References
https://angular.io/guide/http#requesting-non-json-data

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.