【发布时间】:2015-03-05 23:31:05
【问题描述】:
我是 angularjs 的新手,就像许多其他开发人员一样,我是 jquery 开发人员。现在我有一个关于指令的问题。 例如:如果我有这样的指令:
app.directive('mydiv',function(){
return{
restrict:'AE',
template:'<div><ul><li></li><li></li><li></li></ul></div>', //of course in real case it will be use ng-repeat
link:function(scope,element,attr){
}
}
})
我的困惑是,如果我需要访问任何
link: function (scope, element, attrs) { //when hover show the delete icon for each msg and apply highlight class to it.
element.find('li').hover(
function(){
$(this).addClass('highlight');
scope.deleteicon=true;
},
function(){
$(this).removeClass('highlight');
scope.deleteicon=false;
});
}
【问题讨论】:
-
在您的链接函数中,您注入了名为“element”的参数,它将是一个 jqLite 元素。
标签: javascript angularjs dom angularjs-directive angularjs-scope