- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2016 12:16 PM
I am making Service Portal Widget where I retrieve a Knowledge Article Text which is already formatted and styled.
Text, when retrieved from GlideRecord looks like normal HTML, i.e : <p>Test Article</p><br/><div><b>Test Div</b></div> <p>List of current projects:</p><ul><li>List1</li><li>List2</li></ul><br/><p>test2</p>
When I try to assign this value to a div's innerHTML in widget's Body HTML template I get the exact same thing, HTML: <p>Test Article</p><br/><div><b>Test Div</b></div><ul><li>List1</li><li>List2</li></ul><br/><p>test2</p>. I want this to be parsed like any other html and show like:
Test Article
Test Div
List of Current projects:
- List1
- List2
test2
I tried HTML decoding using 2 divs and assigning the value to the innerText first and then copying to the innerHTML of the second, but I always get HTML. Is there something that maybe I can try in the server code before returning the text? I tried a.Text=JSUtil.unescapeText(z.getValue('text')), but still the same. How can I get the browser to parse this string as HTML and not as a text?
Any ideas?
Thanks,
Goran
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2016 12:40 PM
Hi Goran,
You have to use the Angular.js $sce service to render HTML.
In your controller pass in "$sce" to the function:
function($sce) {
var c = this;
c.data.html = $sce.parseAsHtml(data.html)
}
And then in your HTML use:
<div ng-bind-html="c.data.html"></div>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2016 12:40 PM
Hi Goran,
You have to use the Angular.js $sce service to render HTML.
In your controller pass in "$sce" to the function:
function($sce) {
var c = this;
c.data.html = $sce.parseAsHtml(data.html)
}
And then in your HTML use:
<div ng-bind-html="c.data.html"></div>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2016 05:03 PM
Thanks Nathan!