我使用Salesforce作为后端,我的用户可以收到一些通知,其中可能包含带有指向某处的链接的标签的通知。据说我已经在 Controller 中使用了$ sce来完成如下功能:

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

在前端,我这样使用它:
<p ng-bind-html="vm.to_trusted(message.body)"></p>

返回的message.body的示例是
<a href="/#/app/profile">Click Here to Fill out your Profile</a>. It will allow you

在本地主机上,此功能很棒,显示的是链接而不是标签。在Salesforce上,情况并非如此,而是显示上述内容。关于为什么这不起作用的任何想法?

更新:

是的,我确实包括ngSanitize :)

最佳答案

Salesforce @dispatch请求以奇怪的方式序列化文本。

如果Salesforce字符串的内容为:'<a href="">Things</a>',您将在Angular中看到已收到的信息:&lt;a href=&quot;$quot;&gt;Things&lt;a&gt;
我找到的解决方案是在您的 Controller 中:

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

因为Salesforce。

10-07 15:26