小编TJ *_*vis的帖子

如何在不更改标记的情况下仅使用相同的指令定位某些元素?

我现在已经研究了几个小时了.

假设我有一个jQuery选择器$('#bottom .downloads .links a').点击.....

如何在Angular指令中执行相同类型的操作?

这是我到目前为止所做的工作,但适用于页面上的所有标签.

angular.module('directives', []).directive('a', function(mongoDB){ //Don't need ['customServices'], it can just be [] to use mongoDB
return {
    restrict : 'E',
    link : function(scope, element, attrs){     
    element.on('click', function(){
        //But this gets called for all links on the page
                //I just want it to be links within the #bottom .downloads .links div
                //I wanted to use a directive instead of ng-click="someMethod()"
    });
}
Run Code Online (Sandbox Code Playgroud)

});

有没有办法将此指令仅针对某个div?我想我可以将限制更改为'C'或'A'并为链接添加属性,但我想知道我是否仍然可以像我目前习惯使用jQuery选择器一样布局前端.

directive angularjs

2
推荐指数
1
解决办法
1728
查看次数

标签 统计

angularjs ×1

directive ×1