Make a child component to call its parent API in Polymer 1.0.0
I have two web components defined with Polymer 1.0.0 and my question is accessing the parent public API
<dom-module id="x-gallery">
<template is="dom-repeat" items="{{photos}}">
<x-photo photo="{{item}}"></x-photo>
</template>
</dom-module>
<script>
Polymer({
is: 'x-gallery',
...
getAll: function() {
return this.photos;
}
});
</script>
<dom-module id="x-photo">
<template>
<img src="{{photo.src}}">
</template>
</dom-module>
<script>
Polymer({
is: 'x-photo',
properties: {
photo: Object
},
ready: function() {
// HERE ---
// How could I access the x-gallery.getAll public method?
// ...
}
});
</script>
As you can see, I wonder how you could easily access the public method getAll
from children?
I have seen some documentation pertaining to event based solutions (listening to child events), but that doesn't fit my need. Unless you told me there is only one solution available.
Any ideas?
source to share
ready: function() {
this.domHost.getAll()
}
from the documentation: http://polymer.github.io/polymer/
"domHost" is
"whose local dom, which contains this element"
This way you can access the "parent" and its functions. In my opinion, this is the wrong approach within the Polymer.
I've only used it in my project to define callback functions for the parent.
(sorry for my bad english)
source to share