There is a guide on how to create Dart web-ui custom element in Dart code. There is also sample code for this technique
Is there any example on how to create a Dart Polymer custom element from Dart code?
There is an issue saying that a custom element cannot be created using new Element.html()
. But in web-ui there was no need to use new Element.html()
at all. Even though web-ui required writing a few lines of code, but at least it worked. Is there a similar technique for creating Dart Polymer elements from Dart code?
Here is the example code:
import 'dart:html';
import 'package:polymer/polymer.dart';
main() {
querySelector('#add-here').children.add(new Element.tag('my-element'));
}
Notice the use of new Element.tag('my-element')
.
I found a neat little snippet they're using on the source code of chromedeveditor, e.g. here on Github
They use
factory ExampleUi() => new Element.tag('ExampleUi');
so that you could construct the element with:
new ExampleUi();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With