2017-06-14 56 views
0

我必须在我的UI中显示一个工具提示。我在UI端使用angularjs。AngularJS:ng-bind-html里面的uib-tooltip-html

请参阅下面的代码。

<i class="fa fa-info-circle f18 darkgray hover pointer" uib-tooltip-html="'<div class=fw-600>Reason:</div>"+obj.comments+"'" tooltip-class="white-blue-tooltip"></i> 

但是我得到的错误值为obj.comments = Canceled via 'View Group'。请参阅下面的错误。

Error: [$parse:syntax] Syntax Error: Token 'View' is an unexpected token at column 49 of the expression ['<div class=fw-600>Reason:</div>cancelling via 'View Group''] starting at [View Group'']. 

这是因为值中的单引号(通过'View Group'取消)。

为了解决这个问题,如下面的链接描述我用ng-Sanitize https://www.w3schools.com/angular/ng_ng-bind-html.asp

现在我的代码看起来像下面

<i class="fa fa-info-circle f18 darkgray hover pointer" uib-tooltip-html="'<div class=fw-600>Reason:</div> ng-bind-html="+obj.comments+"'" tooltip-class="white-blue-tooltip"></i> 

但我越来越喜欢

Reason: 
ng-bind-html=Canceled via 'View Group' 
输出

我在我的控制器中加入了'ngSanitize',并加载了angular.min.jsangular-sanitize.js在页面中,这里是否有任何缺失。

感谢任何帮助。

回答

0

您必须使用$sce服务。请查看以下链接。

Angularjs Sce

+0

但这是一种替代方法。我想使用ngSanitize,因为它已在整个项目中使用。 –