How to access light DOM in Polymer.dart?

2019-05-10 07:36发布

问题:

I'm looking for a way to access light DOM inside a custom Polymer.dart element.

my_element.html

<link rel="import" href="../../../../packages/polymer/polymer.html">
<polymer-element name="my-element">
  <template>
    <content></content>
  </template>
  <script type="application/dart" src="my_element.dart"></script>
</polymer-element>

my_element.dart

import 'package:polymer/polymer.dart';
import 'dart:html';

@CustomTag('my-element')
class MyElement extends PolymerElement {

  MyElement.created() : super.created() {}

  void attached() {
    // How to access the light DOM of this element?
  }
}

回答1:

To access light DOM simply call this.querySelector('<your-selector>')

To access the shadow DOM call shadowRoot.querySelector('<your-selector>')