Working Example
service.ts
getRawData(): Observable<any> {
const api = 'https://www.w3.org/TR/PNG/iso_8859-1.txt';
return this.httpClient.get(api,{ responseType: 'text' });
}
component.ts
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { AppService } from './app.service';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
name = 'Angular 5';
rawlist: any;
constructor(private appService: AppService) {}
ngOnInit() {}
getRawData() {
this.appService
.getRawData()
.subscribe(
data => this.rawlist=data,
error => console.log(error)
);
}
}
.html
<button (click)="getRawData()">get raw data </button>
{{rawlist }}