angularjs--搜索字高亮显示

在filter.js里面


// 搜索字高亮
manager. filter( "highlight", function( $sce, $log){
var fn = function( text, search){
if (! search) {
return $sce. trustAsHtml( text);
}
text = encodeURI( text);
search = encodeURI( search);
var regex = new RegExp( search, 'gi')
var result = text. replace( regex, '$&');
result = decodeURI( result);
return $sce. trustAsHtml( result);
};
return fn;
});


2、HTML 视图

< p class= "searchBody" ng-bind-html= "everyList.content | highlight:fileLight" > p >


3、css

.highlightedText{
color: #c00;
/* font-weight: 900; */
}

你可能感兴趣的:(angularjs)