2014-10-29 25 views
0

HTML端不顯示作爲HTML:如果響應文本包含HTML意味着如果我們使用angularjs

<div ng-bind-html-unsafe="data.myText"></div> 
 

 
value for data.myText is <span style="text-decoration: underline; color: #cc99ff; background-color: #ff00ff;"><span style="font-family: helvetica; font-size: 24pt;">test</span></span>

作爲預期輸出,需要文本與被顯示以下風格。

但實際上,結果不顯示樣式。

如果有人知道如何解決這個問題,請更新。

+0

效果很好能否請你改一下你的問題?同時提供您的代碼,以及您迄今爲止所嘗試的內容。 – 2014-10-29 05:43:26

+0

請提供您的代碼 – 2014-10-29 05:43:29

+0

是的。請刷新並檢查一次 – 2014-10-29 05:53:53

回答

1

什麼是你的angularjs版本? 1.2,你可以做

<div ng-bind-html='data.myText'></div> 

data.myText必須$sce轉換,你可以注入$sce你控制器,如:

var myCtrl = function($scope, $sce){ 
    $scope.data.myText = $sce.trustAsHtml('value for data.myText is <span style="text-decoration: underline; color: #cc99ff; background-color: #ff00ff;"><span style="font-family: helvetica; font-size: 24pt;">test</span></span>'); 
}; 

,在jsbin example

相關問題