私は次のhtmlを持っています:
<li class="editor" ng-model="post.text" ng-bind-html="post.text" add-class="post.text"></li>
ここで、post.text はラップされた trustedValue で、次のようになります。
開封すると、次のようになります。
次に、trustedValue を検索し、img タグにクラスを追加するディレクティブを作成します。これまでのところ、私はこれを持っています:
function AddClassToImg($sce) {
return {
restrict: 'A',
scope: {
addClass: '='
},
link: function (scope, elem, attrs) {
var content = scope.addClass.$$unwrapTrustedValue();
$(content).find('img').addClass('test');
}
}
};
angular.module('UserProfile')
.directive('addClass', ['$sce', AddClassToImg]);
html から post.text を取得し、それに双方向バインドし、そのクラスの post.text のすべての画像に追加するにはどうすればよいですか?