我有以下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 中的所有图像?