angularjs - HTML 未使用 $sce 和 ng-bind-html 在 Salesforce 上呈现

标签 angularjs salesforce

我使用 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 中看到您收到了:&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。

关于angularjs - HTML 未使用 $sce 和 ng-bind-html 在 Salesforce 上呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38017025/

相关文章:

javascript - 如何从 Angular 加载数据?

salesforce - 使用 soql 从 salesforce 获取选择列表记录

python - 如何接受 JSON POST?

api - Salesforce 何时强制执行文本字段长度?我可以获得实际的字段长度吗?

angularjs - 问号在 Angular 隔离范围绑定(bind)中有什么作用?

javascript - 单击不改变 View

salesforce - 自定义按钮或链接到带有自定义 Controller 的 Visualforce 页面

api - Salesforce EMP 连接器,一段时间后停止接收通知

jquery - jenkins 发送到以下无效地址时出错 :xxx@yyy. com

javascript - 一起使用 jQuery 和 AngularJS?