API响应的字符串无法显示断路线,但是硬码字符串可以显示断路线
美好的一天,
我将Angular 8用作前端,而Java API服务作为我的后端。
我需要从后端检索一些字符串,并且该字符串将在两者之间具有\ n
,例如: pin>##reload。
“指令:\ n1。键在122< 16 digit \ nreload 设置此字符串值如下:
this.str = this.apiRes.responseMsg1;
console.log("this.str : " + this.str);
这将为我提供指令:\ n1。 为1行
在HTML中显示,如果我将此字符串硬编码
this.str = "Instructions:\n1. Key in 122<16 digit \nreload pin># to reload.\n2. Press SEND/CALL from";
console.log("this.str : " + this.str);
,例如:它将给我:
Instructions:
1. Key in 122<16 digit
reload pin># to reload.
2. Press SEND/CALL from
的。
这是我想要 在Google中找到这个答案,但是
我可以知道为什么会发生这种情况?
Good day,
I am using Angular 8 as my frontend, and java api service as my backend.
I need to retrieve some String from backend, and the String will having \n
in between, for example:"Instructions:\n1. Key in 122<16 digit \nreload pin># to reload.\n2. Press SEND/CALL from
In my .ts
file, I am setting this String value as follow:
this.str = this.apiRes.responseMsg1;
console.log("this.str : " + this.str);
This will give me Instructions:\n1. Key in 122<16 digit \nreload pin># to reload.\n2. Press SEND/CALL
, thus when I use it to display in html, it will just display as 1 line.
If I hard code this String to a String variable, for example:
this.str = "Instructions:\n1. Key in 122<16 digit \nreload pin># to reload.\n2. Press SEND/CALL from";
console.log("this.str : " + this.str);
It will give me :
Instructions:
1. Key in 122<16 digit
reload pin># to reload.
2. Press SEND/CALL from
Which is what I want.
I am not really familiar with Angular, I am trying to find this answer in google, but cant get any related result.
May I know why is this happen? And any way I can display the api message accordingly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
html忽略
\ n
线路断裂。基本上,您有两个选择可以解决此问题:&lt; br&gt;
elements替换销售线断裂。白空间的线添加到显示您的字符串的HTML元素中。
HTML ignores
\n
line breaks. You basically have two options to fix this:<br>
elements.white-space: pre-wrap;
to your HTML element which is displaying your string.