I've succedded in dynamically create a polymer component with dart and add to the dom.
But now I would like to do this WITHOUT having to statically import the HTML template at compile time.
In my use case I have a div container with id myContainer
and a custom Polymer Dart component whose tag is my-tag
.
I've tryied with:
LinkElement e = new LinkElement('link');
e.rel = 'import';
e.href= 'my-tag.html';
document.head.children.add(e);
$['myContainer'].children.add(new Element.tag('my-tag'));
But this ends up with the following exception :
Uncaught HierarchyRequestError: Failed to execute 'appendChild' on 'Node': Nodes of type 'HTML' may not be inserted inside nodes of type '#document'.
...
Note that the exception is raisen when the polymer element is added to the dom and not when adding the link tag. Also the same code works if adding the link at compile time and commenting the code that adds it at runtime.
I've tried also with several different variants of the code above, mainly adding the link tag in a separate method called before polymerInit
or inside polymerInit().run(...)
but nothing changes.
I'm wondering if this use case is even supported.
pub build
andpub serve
and can analyze and modify the code during the build process. dartlang.org/tools/pub/assets-and-transformers.html, dartlang.org/tools/pub/transformers – Günter Zöchbauer