I am trying to create a ParagraphElement at run time and it to Div element in a polymer component as follows:
<polymer-element name="my-element" extends="div">
<template>
<p>
<button on-click="updateMessage" data-msg="You clicked Show">Show Message</button>
<button on-click="updateMessage" data-msg="You clicked Hide">Hide Message</button>
<button on-click="addPelement" >Add P element</button>
</p>
<p id="message">{{ message }}</p> <!-- bind the message -->
<div id="mydiv"></div>
</template>
<script type="application/dart" src="my_element.dart"></script>
</polymer-element>
and dart file is as follows:
@CustomTag('my-element')
class MyElement extends PolymerElement with ObservableMixin {
@observable var message;
void updateMessage(Event e, var detail, Element target) {
message = target.attributes['data-msg']; // extract the data- attribute
}
void addPelement(Event e) {
var item = new ParagraphElement ();
item.text="new p element";
DivElement d = query("#mydiv");
d.children.add(item);
}
}
The line query("#mydiv") returns a null element.
needed to add new element to ShadowRoot