Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

polymer

dart

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?

like image 323
Y2i Avatar asked Sep 03 '13 07:09

Y2i


2 Answers

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

like image 172
Seth Ladd Avatar answered Oct 21 '22 09:10

Seth Ladd


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();
like image 22
sthzg Avatar answered Oct 21 '22 10:10

sthzg