uib-popover-html不接受我的html字符串

Yug*_*ryl 8 angularjs angular-ui-bootstrap

我使用角度ui-bootstrap的verion 0.14.2.我无法在弹出窗口中显示行返回.我使用popover-html指令和一个字符串如

Limite inférieure<br>Limite supérieure
Run Code Online (Sandbox Code Playgroud)

它给出以下错误:

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>].
Run Code Online (Sandbox Code Playgroud)

我尝试在$ sce.trustAsHtml调用中包装我的字符串,但它没有改变一件事.

这是一个吸虫 http://plnkr.co/edit/3JSly1anPBUiGyqBcsD1

she*_*lak 18

适合我使用$sce.trustAsHtml如下.

注意:trustAsHtml告诉Angular相信HTML是安全的,所以只有在你信任HTML时才使用它,即它不是用户提供的.

JS:

$scope.popoverContent = $sce.trustAsHtml('Line 1<br>Line2');
Run Code Online (Sandbox Code Playgroud)

HTML:

<button popover-placement="right" uib-popover-html="popoverContent" type="button" class="btn btn-default">Popover</button>
Run Code Online (Sandbox Code Playgroud)

更新了Plunker

或者,如果您的内容是动态的,并且您需要一个功能:

JS:

$scope.input = 'Line 1<br/>Line 2';

var trusted = {};

$scope.getPopoverContent = function(content) {
  return trusted[content] || (trusted[content] = $sce.trustAsHtml(content)); 
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<button popover-placement="right" uib-popover-html="getPopoverContent(input)" type="button" class="btn btn-default">Popover</button>
Run Code Online (Sandbox Code Playgroud)

Plunker

(缓存返回值的原因trustAsHtml是它trustAsHtml始终返回一个新对象,因此可能导致无限$ digest循环)