I am calling a polymer element within another element. The inner polymer element has a published attribute to which I am binding JSON from the parent polymer. However it is not getting reflected.
<polymer-element name="parent-test" attributes="testData">
<template>
This is Parent test
<child-test testdatachild="{{testData}}"></child-test>
</template>
<script>
Polymer('parent-test', {
testData: [],
ready: function () {
debugger;
this.testData = [1, 2, 3, 4]
}
});
</script>
</polymer-element>
<polymer-element name="child-test" attributes="testDataChild">
<template>
<!--{{testDataChild}}-->
<template repeat="{{test in testDataChild}}">
{{test}}
</template>
</template>
<script>
Polymer('child-test', {
testDataChild: [],
ready: function () {
debugger;
}
});
</script>
</polymer-element>I am not sure what could be the problem here.
Seems like I am not having the actual parentContent at the time of generating the child-polymer-element. If I assign hardcoded values in ready function for this.parentContent, it doesnt work as well. If I assign hardcoded values in create function for this parent.Content, it works. So, I am not not sure if this is something related to generating the child polymer element before the values getting binded to parent.
Also, it works if testDataChild is a string and not an array
Seems like I am not having the actual parentContent at the time of generating the child-polymer-element. If I assign hardcoded values in ready function for this.parentContent, it doesnt work as well. If I assign hardcoded values in create function for this parent.Content, it works. So, I am not not sure if this is something related to generating the child polymer element before the values getting binded to parent.
Also, it works if testDataChild is a string and not an array
Hi, I believe you’re hitting the condition where arrays, because they are objects, are shared between every instance of your element in singleton fashion. To work around this you need to not define the array, which will be populated by the attribute binding, in the prototype but instead create them in a “created” call-back inside your element’s script.
The reason you’re seeing it work correctly with strings is because, unlike arrays and objects as I said above, strings and numbers are not shared between instances of your element but are unique to each instance.
Regards,
Daniel Llewellyn
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/19c92ca5-d86f-48a3-9bf0-337173a64d1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.