- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 11:15 PM
Hi all,
there is a html field and the filed value we are showing on portal. When printing the new lines are replaced with
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 02:47 AM
You’re replacing <br/> with actual newline characters. This works in background scripts because it’s a backend context.
However, in the widget (browser/HTML context), the actual newline characters are not rendered visually in HTML. HTML ignores \n and \r\n unless inside elements like <textarea> or when explicitly styled.
1. if you already have <br/> in the value, then just use ng-bind-html in the widget template:
<div ng-bind-html="c.data.description"></div>
2. If you use ng-bind-html, and it doesn’t render the HTML tags properly, inject $sce to trust the content. And add this function on client side.
$scope.trustHtml = function(html) {
return $sce.trustAsHtml(html);
};
and then HTML will be:
<div ng-bind-html="trustHtml(c.data.description)"></div>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 02:45 AM
sorry but with limited context I can't help.
you just shared 2 lines and didn't share what you are doing in that widget, what the complete script looks like, what's your business requirement
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 04:15 AM
Thanks @Ankur Bawiskar for your support as always 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 02:47 AM
You’re replacing <br/> with actual newline characters. This works in background scripts because it’s a backend context.
However, in the widget (browser/HTML context), the actual newline characters are not rendered visually in HTML. HTML ignores \n and \r\n unless inside elements like <textarea> or when explicitly styled.
1. if you already have <br/> in the value, then just use ng-bind-html in the widget template:
<div ng-bind-html="c.data.description"></div>
2. If you use ng-bind-html, and it doesn’t render the HTML tags properly, inject $sce to trust the content. And add this function on client side.
$scope.trustHtml = function(html) {
return $sce.trustAsHtml(html);
};
and then HTML will be:
<div ng-bind-html="trustHtml(c.data.description)"></div>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 04:14 AM
Thanks @Cheikh Ahmadou , it worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 05:29 AM
You're welcome!
Glad i've been helpful.