简体   繁体   中英

How to create an instance of Dart Polymer custom element in Dart code?

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 , eg here on Github

They use

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

so that you could construct the element with:

new ExampleUi();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM