When is shadowRoot available to a polymer component?

前端 未结 2 870
南方客
南方客 2021-01-14 10:19

I\'m having trouble understanding when access to the shadowRoot of a component is available. Here is an image of a set of nested components:

2条回答
  •  醉话见心
    2021-01-14 11:14

    Typically, if you're extending PolymerElement the order of the main callbacks will be ready, created, attached. These happen top-down: they're called on ancestors before descendants. It might confusing that ready is called first, but it's because PolymerElement.created calls it after setting up the DOM and even handlers, and because of constructor ordering that happens before your classes created constructor.

    Polymer also adds a domReady method that you can override which is called when your element's children are guaranteed to have been created. That might be what you need.

    See http://www.polymer-project.org/docs/polymer/polymer.html#lifecyclemethods for details on the lifecycle methods.

    First I would see if you can sidestep the ordering issue with data-binding and declarative events, though.

提交回复
热议问题