angularjs – uib-popover-html不接受我的html字符串
发布时间:2020-12-17 07:34:25 所属栏目:安全 来源:网络整理
导读:我使用角度ui-bootstrap的verion 0.14.2.我无法在弹出窗口中显示行返回. 我使用popover-html指令和一个字符串如 Limite inférieurebrLimite supérieure 它给出以下错误: Lexer Error: Unexpected next character at columns 41-41 [é] in expression [di
我使用角度ui-bootstrap的verion 0.14.2.我无法在弹出窗口中显示行返回.
我使用popover-html指令和一个字符串如 Limite inférieure<br>Limite supérieure 它给出以下错误: Lexer Error: Unexpected next character at columns 41-41 [é] in expression [<div>Approchant des limites<br>Limite supérieure: 34:12<br>Limite inférieure: -34:12</div>]. 我尝试在$sce.trustAsHtml调用中包装我的字符串,但它没有改变一件事. 这是一个掠夺者
使用$sce.trustAsHtml为我工作如下.
注意:trustAsHtml告诉Angular相信HTML是安全的,所以只有在你信任HTML时才使用它,即它不是用户提供的. JS: $scope.popoverContent = $sce.trustAsHtml('Line 1<br>Line2'); HTML: <button popover-placement="right" uib-popover-html="popoverContent" type="button" class="btn btn-default">Popover</button> Updated Plunker 或者,如果您的内容是动态的,并且您需要一个功能: JS: $scope.input = 'Line 1<br/>Line 2'; var trusted = {}; $scope.getPopoverContent = function(content) { return trusted[content] || (trusted[content] = $sce.trustAsHtml(content)); } HTML: <button popover-placement="right" uib-popover-html="getPopoverContent(input)" type="button" class="btn btn-default">Popover</button> Plunker (缓存trustAsHtml返回的值的原因是trustAsHtml总是返回一个新对象,因此可能导致无限$digest循环) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |