0
我試圖通過在角度過濾器上動態添加span元素來強調搜索詞。我相信與$sce
的HTML,但我仍然得到一個錯誤:Error: [$sce:unsafe] http://errors.angularjs.org/1.4.7/$sce/unsafe
這是我(簡化):
html元素:
<span ng-bind-html="entity.desc | filter:highlight(search)"></span>
指令:
scopePicker = ($sce) ->
return {
restrict: 'E'
scope: {
...
}
templateUrl: 'my.html'
link: (scope, element, attributes, controller) ->
scope.highlight = (string) -> (desc) ->
return trustAsHtml(desc) unless string
return trustAsHtml(desc.replace(string, '<span class="highlighted">' + string + '</span>'))
return
}
angular
.module('scopePicker')
.directive('sScopePicker', ['$sce', scopePicker])