gpt4 book ai didi

angularjs - angular.js 元素没有方法 querySelector

转载 作者:行者123 更新时间:2023-12-02 03:50:28 26 4
gpt4 key购买 nike

我试图从 Angular 获取一个子元素作为我的指令中的对象,所以我有

link: function(scope,elem,attrs){    var resizeBar = elem.querySelector('.resize-bar');

When I output the elem, I have an html object. However, I get an error `Object [object object] has no method 'querySelector'.

I can get the element using

   var resizeBar = elem.children().children()[1];

but that outputs as

<div class="resize-bar">Move</div>

这不是我需要的,我需要调整大小栏的 html 对象。

有人知道在 Angular 上做到这一点的好方法吗?

elem 的控制台输出是

: div.favor-layout.favor-layout-sidewaysaccessKey: ""align: ""attributes: NamedNodeMapbaseURI: "file:///C:/Users/pete/projects/favor/favor-layout/index.html"childElementCount: 1childNodes: NodeList[2]children: HTMLCollection[1]classList: DOMTokenListclassName: "favor-layout favor-layout-sideways"clientHeight: 200clientLeft: 0clientTop: 0clientWidth: 913contentEditable: "inherit"dataset: DOMStringMapdir: ""draggable: falsefirstChild: div.favor-layout-containerfirstElementChild: div.favor-layout-containerhidden: falseid: ""innerHTML: "↵   ↵          This gets wrapped.↵     ↵ move↵↵"innerText: "This gets wrapped.↵move"isContentEditable: falselang: ""lastChild: textlastElementChild: div.favor-layout-containerlocalName: "div"namespaceURI: "http://www.w3.org/1999/xhtml"nextElementSibling: nullnextSibling: textnodeName: "DIV"nodeType: 1nodeValue: nulloffsetHeight: 200offsetLeft: 8offsetParent: body.ng-scopeoffsetTop: 8offsetWidth: 913onabort: nullonbeforecopy: nullonbeforecut: nullonbeforepaste: nullonblur: nulloncancel: nulloncanplay: nulloncanplaythrough: nullonchange: nullonclick: nullonclose: nulloncontextmenu: nulloncopy: nulloncuechange: nulloncut: nullondblclick: nullondrag: nullondragend: nullondragenter: nullondragleave: nullondragover: nullondragstart: nullondrop: nullondurationchange: nullonemptied: nullonended: nullonerror: nullonfocus: nulloninput: nulloninvalid: nullonkeydown: nullonkeypress: nullonkeyup: nullonload: nullonloadeddata: nullonloadedmetadata: nullonloadstart: nullonmousedown: nullonmouseenter: nullonmouseleave: nullonmousemove: nullonmouseout: nullonmouseover: nullonmouseup: nullonmousewheel: nullonpaste: nullonpause: nullonplay: nullonplaying: nullonprogress: nullonratechange: nullonreset: nullonscroll: nullonsearch: nullonseeked: nullonseeking: nullonselect: nullonselectstart: nullonshow: nullonstalled: nullonsubmit: nullonsuspend: nullontimeupdate: nullonvolumechange: nullonwaiting: nullonwebkitfullscreenchange: nullonwebkitfullscreenerror: nullonwheel: nullouterHTML: "↵   ↵          This gets wrapped.↵     ↵ move↵↵"outerText: "This gets wrapped.↵move"ownerDocument: documentparentElement: body.ng-scopeparentNode: body.ng-scopeprefix: nullpreviousElementSibling: nullpreviousSibling: textscrollHeight: 200scrollLeft: 0scrollTop: 0scrollWidth: 913spellcheck: truestyle: CSSStyleDeclarationtabIndex: -1tagName: "DIV"textContent: "↵ ↵           This gets wrapped.↵     ↵   move↵↵"title: ""translate: truewebkitPseudo: ""webkitShadowRoot: nullwebkitdropzone: ""__proto__: HTMLDivElementcontext: div.favor-layout.favor-layout-sidewayslength: 1__proto__: Object[0]

最佳答案

试试这个,返回值是元素,而不是 Angular 元素。

var resizeBar = elem[0].querySelector('.resize-bar');

关于angularjs - angular.js 元素没有方法 querySelector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21082715/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com