0
<div data-ng-bind-html="message | myFilter"></div> <!-- it does not work -->
<img data-my-directive src="xxx.jpg" alt="some captions"/> <!-- it works -->
angular.module('core').filter('myFilter', ['jQuery',
function ($) {
return function (message) {
var $img = $('<img data-my-directive/>'):
$img.attr({src : 'xxx.jpg', alt : message});
return $('<div/>').append($img).html();
}
}
]);
angular.module('core').directive('myDirective', [
function() {
return {
restrict : 'A',
link : function (scope, $element, attrs) {
$element.someJQueryPlugin();
}
}
}
]);
から返されたそれは、もともとから来たので、二<img/>
が正常に動作しながら、それは、フィルタから接続されている場合、私はmyDirective
と最初<img/>
作品を取得することはできませんテンプレートファイル。は、上記の例からフィルタ
第2の<img/>
の問題を解決するための回避策もありますか?
このようにして<img/>
をどうして作る必要があるのか尋ねないでください。それは単なる例です。 $compile
サービスを示唆ため@charlietfl
「ng-bind-html」は生のhtmlだけの角度指令を補間するものではありません。回避策のある関連する他の多くの記事があります。それは私の場合は、自分の指示を使用する代わりに、あなたは自分自身をコンパイルすることができます – charlietfl