Paper Dart Instances

How can I get an instance of the paper-input element below?

HTML file:

 <!DOCTYPE html> <html> <head> <!-- <script src='packages/web_components/platform.js'></script> not necessary anymore with Polymer >= 0.14.0 --> <script src='packages/web_components/dart_support.js'></script> <link rel='import' href='packages/paper_elements/paper_input.html'> <script src='packages/browser/dart.js'></script> </head> <body fullbleed unresolved> <paper-input id='subject' label='subject'></paper-input> <script type='application/dart' src='myscript.dart'></script> </body> </html> 

myscript.dart:

 import 'dart:html'; import 'package:polymer/polymer.dart'; import 'package:paper_elements/paper_input.dart'; export 'package:polymer/init.dart'; PaperInput _subject = querySelector('#subject'); // exception void main() { ... } 

This throws an exception:

 Breaking on exception: type 'HtmlElement' is not a subtype of type 'PaperInput' 

Sending from HtmlElement to PaperInput does not work. Suggestions included the use of shadowRoot.querySelector('#subject'); and other shadowRoot customs, but where did they come from? If I add .shadowRoot.querySelector('paper-input') to the last line of myscript.dart, the element will be zero. Same result if I use identifier instead of tag name. The element itself is the top level for the html body, so it is not in any other shadowRoot.

Cannot get paper-input content without its PaperInput class. But there seems to be no way to drop him.

+2
source share
1 answer

You launch how to implement the main function in polymer applications

If you do this as shown below or inside the Polymer element ( attached() after super.attached() or in some click or other event handler (when the element is correctly initialized)

 main() { initPolymer().run(() { // code here works most of the time Polymer.onReady.then((_) { // some things must wait until onReady callback is called // for an example look at the discussion linked below PaperInput _subject = querySelector('#subject'); }); }); } 
+4
source

Source: https://habr.com/ru/post/971493/


All Articles