I have a polymer-element like this:
<polymer-element name="x-block" attributes="data">
<template>
<div class="block-wrapper">
<div class="plus-button"on-click="{{showMdl}}">+</div>
<div hidden?="{{!showModal}}" id="modal">
Modal
</div>
<content select="header"></content>
</div>
</template>
/*Polymer */
<script>
Polymer({
ready: function(){
this.showModal = false;
},
showMdl: function(e,detail,sender){
this.showModal = true;
this.$.modal.style.top = e.layerY+'px';
this.$.modal.style.left = e.layerX+'px';
var newElement = document.createElement('div')
newElement.innerHTML = 'dynamicllyElement';
newElement.setAttribute('on-click','{{clickOnDynamicllyElement}}');
this.$.modal.appendChild(newElement);
},
clickOnDynamicllyElement:function(){
console.log('1111')
}
});
</script>
</polymer-element>
clickOnDynamicllyElement
does not work.
newElement.addEventListener('click', this.
clickOnDynamicllyElement);
learn js and domFollow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/d39e75e3-65a1-4637-837c-f3ece533acb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/b48b3b1c-0179-402b-9742-195fafca0d0a%40googlegroups.com.
this.injectBoundHTML('<div on-click="{{clickOnDynamicllyElement}}">dynamicllyElement</div>', this.$.modal);
https://www.polymer-project.org/docs/polymer/polymer.html#imperativeregister
Registering imperatively Elements can be registered in pure JavaScript like this:
<script>
Polymer('name-tag', {nameColor: 'red'});
var el = document.createElement('div');
el.innerHTML = '\
<polymer-element name="name-tag" attributes="name">\
<template>\
Hello <span style="color:{{nameColor}}">{{name}}</span>\
</template>\
</polymer-element>';
// The custom elements polyfill can't see the <polymer-element>
// unless you put it in the DOM.
document.body.appendChild(el);
</script>
You need to add the to the document so that the Custom Elements polyfill picks it up.
Important: Since the Polymer call here is outside the , it must include the tag name argument.
<polymer-element name="x-block" attributes="data">
<template>
<div class="block-wrapper">
<div class="plus-button"on-click="{{showModal}}">+</div>
<div id="modal" hidden?="{{!modalShown}}" style="modalTop: {{top}}px; modalLeft: {{left}}px;">
Modal
</div>
<content select="header"></content>
</div>
</template>
/*Polymer */
<script>
Polymer({
ready: function(){
this.modalShown = false;
},
showModal: function(e) {
this.modalShown = true;
this.modalTop = e.layerY;
this.modalLeft = e.layerX;
//
var newElement = document.createElement('div')
newElement.innerHTML = 'dynamicElement';
newElement.addEventListener('click', this.dynamicElementClick.bind(this));
this.$.modal.appendChild(newElement);
},
dynamicElementClick: function(){
console.log('1111')
}
});
</script>
</polymer-element>
Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/e7e9b248-f42a-4320-acbd-882ef90d6a4d%40googlegroups.com.