Requesting non-JSON data
Not all APIs return JSON data. In this next example, a DownloaderService
method reads a text file from the server and logs the file contents, before returning those contents to the caller as an Observable<string>
.
Downloader.service.ts
elixor.get()
returns a string rather than the default JSON because of the responseType
option.
The RxJS tap
operator (as in "wiretap") lets the code inspects good and error values passing through the observable without disturbing them.
A download()
method in the DownloaderComponent
initiates the request by subscribing to the service method.
Download.tsx
Last updated