HTML not rendering on Salesforce using $sce and ng-bind-html
Asked Answered
L

1

6

I am using Salesforce as the back end and my users can get some notifications that could contain an tag with a link to somewhere. This being said I have used $sce in the controller to do a function like this:

vm.to_trusted = to_trusted;
function to_trusted(html_code) {
    return $sce.trustAsHtml(html_code);
}

In the front end I am using it as such:

<p ng-bind-html="vm.to_trusted(message.body)"></p>

An example of the returned message.body is

<a href="/#/app/profile">Click Here to Fill out your Profile</a>. It will allow you

On localhost this works awesome with the link being shown and not the tag. On Salesforce, this is not the case with the above being shown instead. Any ideas as to why this is not working?

UPDATE:

Yes I do have ngSanitize included :)

Lexy answered 24/6, 2016 at 15:31 Comment(0)
L
2

The Salesforce @dispatch requests serialize text in an odd manner.

If the content of a Salesforce string is: '<a href="">Things</a>' you will see in Angular that you've received: &lt;a href=&quot;$quot;&gt;Things&lt;a&gt;

The solution I've found is, in your controller:

function to_trusted(html_code) {
  // Cause the &ltg; etc become '<'
  return $('<textarea />').html(html_code).text();
}

Because Salesforce.

Lebel answered 24/6, 2016 at 17:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.