How to instantiate a custom Dart Polymer element in Dart code?

There is a guide on how to create a custom Dart web-ui element in Dart code. There is also sample code for this method.

Is there any example of how to create a custom Dart Polymer element from Dart code? There is an issue saying that a custom element cannot be created using new Element.html() . But in web-ui it was not necessary to use new Element.html() at all. Despite the fact that web-ui required writing a few lines of code, but at least it worked. Is there a similar method for creating Dart Polymer elements from Dart code?

+7
dart polymer
source share
2 answers

Here is a sample code:

 import 'dart:html'; import 'package:polymer/polymer.dart'; main() { querySelector('#add-here').children.add(new Element.tag('my-element')); } 

Note the use of new Element.tag('my-element') .

+15
source share

I found a neat little snippet that they use in the chromedeveditor source code, for example, here on Github

They use

 factory ExampleUi() => new Element.tag('ExampleUi'); 

so you can build an element with:

 new ExampleUi(); 
+1
source share

All Articles