指示
app.directive('mcAvatar', function() {
return {
restrict: 'E',
scope: {
width: '=width',
src: '@src'
},
templateUrl: 'directives/mc-avatar/mc-avatar.html',
link: function (scope, element, attrs) {
console.log(element[0])
}
};
});
模板
<img width="{{ width }}" src="{{ src }}" alt="" class="mc-avatar-round">
用法
<mc-avatar width="50" src="http://lorempixel.com/320/320/cats"></mc-avatar>
element
指令中的内部链接函数返回:
<mc-avatar width="50" src="http://lorempixel.com/320/320/cats" class="ng-isolate-scope">
<img width="50" src="http://lorempixel.com/320/320/cats" alt="" class="mc-avatar-round">
</mc-avatar>
仅给出上下文mg-avatar
。如何访问img
此处的元素以便我可以使用bind
函数?