[英]AngularJS : ng-bind-html inside a uib-tooltip-html
我必須在用戶界面中顯示工具提示。 我在UI端使用angularjs。
請參見下面的代碼。
<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''].
這是因為值中存在單引號(通過“視圖組”取消)。
為了解決這個問題,我使用了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.js
和angular-sanitize.js
,這里缺少任何內容。
感謝任何幫助。
您必須使用$sce
服務。 請查看以下鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.