How to create an instance of Dart Polymer custom e

2019-02-09 15:11发布

问题:

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?

回答1:

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').



回答2:

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();


标签: dart polymer