如何在 AngularJS 控制器中获取当前范围的 dom 元素? [英] How do I get current scope dom-element in AngularJS controller?

查看:48
本文介绍了如何在 AngularJS 控制器中获取当前范围的 dom 元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个outerItems的列表.在每个外部项目中,我有一个内部项目列表.它们是动态排序的.

I have a list of outerItems. Inside each outerItem, I have a list of innerItems. They are dynamically sorted.

当鼠标光标指向innerItems之一时,我必须在该innerItem元素正上方显示弹出窗口.

When mouse cursor points at one of innerItems, I have to show the popup window right above that innerItem element.

Popup div 是 body 的孩子,因为我不想为每个 innerItems 有一个单独的弹出窗口.

Popup div is body's child, because I do not want to have a separate popup for each of innerItems.

我所看到的方式 — 在 ng-mouseover 上,我调用了将左/上属性设置为绝对定位弹出窗口的函数.因此,对于每个innerItems,我想调用jQuery .offset() 方法,该方法从页面的左上角为我提供left/top 值.

The way as I see it — on ng-mouseover I call the function that sets left/top properties to my absolutely positioned popup. So for each of innerItems I'd like to call jQuery .offset() method that gives me left/top values from the top-left corner of page.

那么如何获取当前作用域元素的 jQuery 对象呢?或者,如果我选择了错误的方式

So how can I get jQuery object of current scope element? Or, if I've chosen the wrong way

推荐答案

在控制器中:

function innerItem($scope, $element){
    var jQueryInnerItem = $($element); 
}

这篇关于如何在 AngularJS 控制器中获取当前范围的 dom 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆