正确的使用方法是popver-html
指示?
我想通过 HTML 显示图像 img
标记到我的弹出窗口 Angular-Bootstrap 中。
我创建了一个范围变量 $scope.html = "<img src=\""+$scope.mysrc+"\"></img>"
我已将其放入我的指令中
<span popover-html="{{html}}" popover-title="......." popover-trigger="mouseenter"><a href="#">{{title}}</a></span>
但我有这个错误:
Uncaught Error: [$parse:syntax] ERROR popover-html
有什么建议吗?
最佳答案
这是一个plunk指导您如何将图像放入弹出窗口中。寻找“Dynamic Popover
”按钮
首先,您需要sanitize你的HTML
您在JS
中写的.
所以,你的 JS 是这样的:
$scope.html = $sce.trustAsHtml("<img src=\""+$scope.mysrc+"\"></img>");
这将确保您的 HTML 可以安全地解析为 HTML。不要忘记注入(inject)ngSanitize
在您的应用程序中作为依赖项。
现在,在您看来,而不是使用
popover-html="{{html}}"
,您需要使用popover-html="html"
。请注意,您正在向此弹出窗口传递一个表达式。
关于javascript - 带有 html 的 Angular 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33243551/