I have created a custom web component with Polymer, that wraps text and alters it slightly (transforming to uppercase in this proof of concept).
The element itself works OK with static content. However, when the content is dynamically binded, the component fails to show the content.
For example:
<my-wrapper>Hello, World!</my-wrapper> <!-- Works -->
<my-wrapper>[[someText]]</my-wrapper> <!-- Doesn't work -->
Currently I am using observeNodes, which manages to trigger the initial text transform, but fails to trigger sub-sequential changes.
My current prototype is defined as:
<dom-module id="my-wrapper">
<template>
<span id="placeholder"></span>
</template>
<script>
Polymer({
is: 'my-wrapper',
ready: function() {
var self = this;
Polymer.dom(Polymer.dom(this)).observeNodes(function(info) {
self.$.placeholder.textContent = info.target.textContent.toUpperCase();
});
/*var mutationObserver = new MutationObserver(function(e) {
console.log(e);
});
mutationObserver.observe(this.root, {characterData: true, childList: true});*/
},
});
</script>
</dom-module>
And a working JSBin for the aforementioned problem can be found here: http://jsbin.com/jumewuzuho/1/edit?html,console,output.
Any suggestions on how to capture the change of the (light DOM) content, so that I can re-transform the text?
As you can see in the commented block of code, I have already tried using MutationObserver, but failed to create a working prototype. My guess is that I didn't used the correct node (this.root
in my case).
template
tag along with theTemplatizer
behavior, but failed to produce any useful results. – Molarity