I'm trying to get a child element from angular as an object in my directive, so I have
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>
which isn't what I need, I need the html object of the resize-bar.
Anybody know of a good way to do this in angular?
console output of elem is
: div.favor-layout.favor-layout-sideways accessKey: "" align: "" attributes: NamedNodeMap baseURI: "file:///C:/Users/pete/projects/favor/favor-layout/index.html" childElementCount: 1 childNodes: NodeList[2] children: HTMLCollection[1] classList: DOMTokenList className: "favor-layout favor-layout-sideways" clientHeight: 200 clientLeft: 0 clientTop: 0 clientWidth: 913 contentEditable: "inherit" dataset: DOMStringMap dir: "" draggable: false firstChild: div.favor-layout-container firstElementChild: div.favor-layout-container hidden: false id: "" innerHTML: "↵ ↵ This gets wrapped.↵ ↵ move↵↵" innerText: "This gets wrapped.↵move" isContentEditable: false lang: "" lastChild: text lastElementChild: div.favor-layout-container localName: "div" namespaceURI: "http://www.w3.org/1999/xhtml" nextElementSibling: null nextSibling: text nodeName: "DIV" nodeType: 1 nodeValue: null offsetHeight: 200 offsetLeft: 8 offsetParent: body.ng-scope offsetTop: 8 offsetWidth: 913 onabort: null onbeforecopy: null onbeforecut: null onbeforepaste: null onblur: null oncancel: null oncanplay: null oncanplaythrough: null onchange: null onclick: null onclose: null oncontextmenu: null oncopy: null oncuechange: null oncut: null ondblclick: null ondrag: null ondragend: null ondragenter: null ondragleave: null ondragover: null ondragstart: null ondrop: null ondurationchange: null onemptied: null onended: null onerror: null onfocus: null oninput: null oninvalid: null onkeydown: null onkeypress: null onkeyup: null onload: null onloadeddata: null onloadedmetadata: null onloadstart: null onmousedown: null onmouseenter: null onmouseleave: null onmousemove: null onmouseout: null onmouseover: null onmouseup: null onmousewheel: null onpaste: null onpause: null onplay: null onplaying: null onprogress: null onratechange: null onreset: null onscroll: null onsearch: null onseeked: null onseeking: null onselect: null onselectstart: null onshow: null onstalled: null onsubmit: null onsuspend: null ontimeupdate: null onvolumechange: null onwaiting: null onwebkitfullscreenchange: null onwebkitfullscreenerror: null onwheel: null outerHTML: "↵ ↵ This gets wrapped.↵ ↵ move↵↵" outerText: "This gets wrapped.↵move" ownerDocument: document parentElement: body.ng-scope parentNode: body.ng-scope prefix: null previousElementSibling: null previousSibling: text scrollHeight: 200 scrollLeft: 0 scrollTop: 0 scrollWidth: 913 spellcheck: true style: CSSStyleDeclaration tabIndex: -1 tagName: "DIV" textContent: "↵ ↵ This gets wrapped.↵ ↵ move↵↵" title: "" translate: true webkitPseudo: "" webkitShadowRoot: null webkitdropzone: "" __proto__: HTMLDivElement context: div.favor-layout.favor-layout-sideways length: 1 __proto__: Object[0]
try this, the return value is element, not angular element.
var resizeBar = elem[0].querySelector('.resize-bar');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With