0

From my web api, I can see there is formatting for line breaks etc, as below:

address: "11 Ingle Park Way↵LONDON↵NN15 1GN↵United Kingdom"

What I want to know is, how to I bind the data to my view with this formatting. So far I am doing:

<span class="text-gray">{{receivedRequest.address}}</span>

TS file

receivedRequest: any;

constructor(private service: nowService,
    private appComponent: AppComponent,
    private userService: UserService,
    private router: Router,
    private http: HttpClient,
    private route: ActivatedRoute
  ) {
    this.receivedRequest = { number: '', opened_at: '', description: '', short_description: '', "c_i.serial_number" : "value" }; this.receivedLocation = { city: null, country: null }
  }

private getRequest() {
    this.service.getServiceRequest(this.s_id, this.c_id).subscribe((data) => {
      this.loading = true;
      console.log('Result - ', data);
      console.log('service data is received');
      this.loading = true;
      this.receivedRequest = data.result;
      this.loading = false;
    })
  }

.service file

getServiceRequest(s_id, cId): Observable<any> {
    return this.http.get<any>(this.servicenowApiUrl + "/" + s_id + "?c_id=" + cId)
      .pipe(
        catchError(this.handleError)
      );
  }
10
  • You need to replace the text line breaks with actual <br> elements, or they'll get rendered to single spaces like virtually all other whitespace in HTML. Commented Apr 10, 2019 at 15:54
  • 1
    Unless you want to do it on the server side, but that would likely make it less useful for any non-HTML-based clients. Commented Apr 10, 2019 at 15:56
  • 1
    No, I'm saying you probably shouldn't do it server-side. Commented Apr 10, 2019 at 16:00
  • 1
    Try to replace your span tag with a pre tag Commented Apr 10, 2019 at 16:09
  • 1
    That worked Alessandro, can you add as answer and I can accept Commented Apr 10, 2019 at 16:13

1 Answer 1

1

As you can read here

The HTML pre element represents preformatted text which is to be presented exactly as written in the HTML file. The text is typically rendered using a non-proportional ("monospace") font. Whitespace inside this element is displayed as written.

As you can find below, you can replace your span tag with a pre tag

<pre class="text-gray">{{receivedRequest.address}}</pre>

and preserve the existent format of your text without modify your api endpoint.

All the best

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.