I am trying to display a string in a paragraph and this string contains
for the purpose of displaying it new line.
But only thing i am getting is br tag when i intend to break the line.
This is my TypeScript method.
viewEmailMessage(messageId: number): void {
console.log(messageId);
this.previewEmailMessage = new EmailMessage();
this.previewEmailMessage = this.emailMessageList.filter(item => item.id == messageId)[0];
console.log(this.previewEmailMessage);
this.previewEmailMessage.message = this.previewEmailMessage.message.replace(/(\n)+/g, '<br>');
this.previewEmailMessage.signature = this.previewEmailMessage.signature.replace(/(\n)+/g,'<br>')
}
HTML:
<div class="modal fade" id="preview-send" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Preview</h4>
</div>
<div class="modal-body">
<div class="preview-content">
<div class="title">
<h2>{{previewEmailMessage.title}}</h2>
</div>
<div class="subject">
<p>{{previewEmailMessage.subject}}</p>
</div>
<div class="description">
<p>{{previewEmailMessage.message}}</p>
</div>
<div class="signature-wrap">
<p>{{previewEmailMessage.signature}}</p>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn default-btn" data-dismiss="modal">Send</button>
</div>
</div>
</div>
</div>
How can I display this on new line whenever line break occur in html.
One way to do it is to set the paragraph content with [innerHTML]
:
<p [innerHTML]="previewEmailMessage.message"></p>
See this stackblitz for a demo.
If this is the salesforce API, you can try using this.previewEmailMessage.HtmlBody
instead. Can't immediately remember if there was a signature HTML field as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.