ディレクティブでトランスクルードされたテキストにフィルターを適用しようとしていますが、これを行う最善の方法がわかりません。アイデアの作業コピーは次のリンクにありますが、コンパイル機能を使用してトランスクルージョンされたテキストを取得することで、不正行為をしているように感じます。JSFiddleを参照してください。
angular.module("MyApp").directive('highlighter', function () {
return {
restrict: 'E',
replace: true,
transclude: true,
scope: {
phrase: '@',
text: '@'
},
template: '<span ng-bind-html-unsafe=" text | highlight:phrase:false "></span>',
compile: function (elem, attr, transclude) {
transclude(elem, function (clone) {
// grab content and store in text attribute
var txt = clone[0].textContent;
attr.text = txt;
});
}
};
});