How to handle plain text server response in Angular 2?
I am using the following:
this.http.get('lib/respApiTest.res')
.subscribe(testReadme => this.testReadme = testReadme);
lib/respApiTest.res
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
But I am getting a JSON format example:
{"_body":"Lorem ipsum dolor sit amet......"}
Right now I'm using something like the following to handle: (this.testReadme._boby)
alert(this.testReadme._boby);
This works well but is this the way to handle plain text in Angular 2 ?
Use response.text()
method...
this.http.get('lib/respApiTest.res')
.subscribe(testReadme => this.testReadme = testReadme.text());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With