Angular绑定Web API格式

时间:2019-04-10 15:52:41

标签: html angular

从我的Web API中,我可以看到换行符等格式,如下所示:

SHA512_Update (&mdContext, data, bytes);

我想知道的是如何使用这种格式将数据绑定到视图。到目前为止,我正在这样做:

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

TS文件

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

.service文件

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;
    })
  }

1 个答案:

答案 0 :(得分:1)

您可以阅读here

  

HTML pre 元素表示要预先格式化的文本   完全按照HTML文件中的文字显示。文字通常是   使用非比例(“等宽”)字体呈现。空格   

因此您可以将 span 标记替换为 pre 标记

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

并保留文本的现有格式,而无需修改api端点。

祝一切顺利