Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle plain text, server response in Angular 2?

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 ?

like image 368
Angel Angel Avatar asked Dec 14 '22 08:12

Angel Angel


1 Answers

Use response.text() method...

this.http.get('lib/respApiTest.res')
  .subscribe(testReadme => this.testReadme = testReadme.text());
like image 79
Sasxa Avatar answered Dec 18 '22 10:12

Sasxa