馬克向上返回的HTML:顯示輸出,它包含可從過濾功能
<div class="vpScoreInner" ng-bind-html="reason | truncate:limit:20:" ...">
JS:
filter('truncate', function($sce){
return function(text, overall_limit, line_limit, end){
if (!text){
return;
}
var last_blank_index = 0;
var line_length = 0;
var overall_length = 0;
var processed = '';
var componenets = text.split(' ');
for (var i = 0; i < componenets.length; i++){
c = componenets[i];
if (overall_limit && overall_length + c.length >= overall_limit){
return $sce.trustAsHtml(processed + end);
}
if(line_length < line_limit){
processed = !!processed ? processed + ' ' + c : c;
line_length = line_length + c.length;
}
else{
processed = processed + '<br>'
line_length = 0
}
overall_length = overall_length + c.length;
}
return $sce.trustAsHtml(processed);
}
});
這個過濾器我實現了在需要時都截斷文本,並分割它在不超過x個字符的行中沒有在中間切割詞。
問題是,與正常的ng綁定
標記呈現爲純文本,並使用相對較新的ng-bind-html,文本根本不呈現。
你在這裏嘗試了答案:http://stackoverflow.com/questions/ 14726938/angular-sanitize-ng-bind-html-not-working –