問題
カスタム ディレクティブを介してng-bind属性を動的に追加し、どこでもテンプレート定義に手動で追加することなく、カスタム ディレクティブでng-bind、ng-bind-html、またはng-bind-html-unsafeを使用できるようにします。
例
http://jsfiddle.net/nstuart/hUxp7/2/
壊れたディレクティブ
angular.module('app').directive('bindTest', [
'$compile',
function ($compile) {
return {
restrict: 'A',
scope: true,
compile: function (tElem, tAttrs) {
if (!tElem.attr('ng-bind')) {
tElem.attr('ng-bind', 'content');
$compile(tElem)
}
return function (scope, elem, attrs) {
console.log('Linking...');
scope.content = "Content!";
};
}
};
}]);
解決
わかりません。上記のフィドルのようなものが機能しない理由が本当にわかりません。そこに余分な$compileがある場合とない場合で試してみました。
回避策
ディレクティブにテンプレート値を追加することで回避できますが、それはコンテンツを余分な div でラップするため、可能であればそれを可能にしたいと考えています。(フィドルを参照)
2 番目の回避策
ここでフィドルを参照してください: http://jsfiddle.net/nstuart/hUxp7/4/ (以下のイカルス博士の提案による)。リンク機能に到達する前にテンプレートを変更し、変更を見つけて適用する必要があるように感じるので、これを現在の回避策と考えています。