angular.dart icon indicating copy to clipboard operation
angular.dart copied to clipboard

Need a reliable way to query a component's child elements when useShadowDom = false

Open bgourlie opened this issue 10 years ago • 4 comments

In scenarios where useShadowDom is set to false, there's no reliable way to know when a component's template has been loaded into the DOM, and therefore no reliable way to query for child elements. Please see this detailed SO question for more details:

http://stackoverflow.com/questions/27988813/querying-child-elements-of-a-component-when-useshadowdom-false

bgourlie avatar Jan 16 '15 17:01 bgourlie

I think in this case you should either use document.querySelector() or use the _root you inject in the 2nd code snippet inside onShadowRoot like _root.querySelector(). If there isn't a `shadowRoot you can't use it as an anchor for querying. (I also commented on the answer to your SO question)

zoechi avatar Jan 21 '15 13:01 zoechi

I did attempt to query the _root element injected via constructor in the onShadowRoot method (see the edit in my SO question). It seems to me that when constructing the EmulatedShadowRoot (shadowDom: false and implement ShadowRootAware) the web platform shim attempts to do some stuff that is failing, even when not querying the shadowRoot object.

bgourlie avatar Jan 21 '15 14:01 bgourlie

Assigning to Victor to reply with a more comprehensive answer

naomiblack avatar Jan 21 '15 19:01 naomiblack

@bgourlie see my answer http://stackoverflow.com/questions/27988813/querying-child-elements-of-a-component-when-useshadowdom-false

vsavkin avatar Jan 26 '15 22:01 vsavkin