jQuery的发现()方法AngularJS指令不工作 [英] jQuery find() method not working in AngularJS directive

查看:127
本文介绍了jQuery的发现()方法AngularJS指令不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有angularjs指示找到与注入的角度子元素的DOM元素的麻烦。

I am having trouble with angularjs directives finding child DOM elements with the injected angular element.

例如我有一个指令,像这样:

For example I have a directive like so:

myApp.directive('test', function () {
    return {
        restrict: "A",
        link: function (scope, elm, attr) {
            var look = elm.find('#findme');
             elm.addClass("addedClass");
            console.log(look);
        }
    };
});

和HTML,例如:

<div ng-app="myApp">
    <div test>TEST Div
        <div id="findme"></div>
    </div>
</div>

我有权访问哪些是通过将一类到它proffed的元素。
但是试图访问一个子元素产生在var看空数组。

I have access to the element which is proffed by adding a class to it. However attempting to access a child element produces an empty array in the var look.

的jsfiddle演示是这里

为什么东西那么微不足道工作不正常?

Why is something so trivial not working properly?

推荐答案

文档角.element

找到() - 由标签名限于查找

find() - Limited to lookups by tag name

所以,如果你不使用jQuery有棱有角,但依靠其jqlite实现,你不能做 elm.find('#someid')

So if you're not using jQuery with Angular, but relying upon its jqlite implementation, you can't do elm.find('#someid').

您有机会获得儿童()内容()数据()实现,所以通常可以找到变通的办法。

You do have access to children(), contents(), and data() implementations, so you can usually find a way around it.

这篇关于jQuery的发现()方法AngularJS指令不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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