我使用 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
在 localhost 上,这与显示的链接而不是标签一起工作非常好。在 Salesforce 上,情况并非如此,而是显示了上述内容。关于为什么这不起作用的任何想法?
更新:
是的,我确实包含了 ngSanitize :)
最佳答案
Salesforce @dispatch
请求以奇怪的方式序列化文本。
如果 Salesforce 字符串的内容是:'<a href="">Things</a>'
您将在 Angular 中看到您收到了:<a href="$quot;>Things<a>
我找到的解决方案是,在您的 Controller 中:
function to_trusted(html_code) {
// Cause the <g; etc become '<'
return $('<textarea />').html(html_code).text();
}
因为 Salesforce。
关于angularjs - HTML 未使用 $sce 和 ng-bind-html 在 Salesforce 上呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38017025/