I have a custom element <y-list>
which fires an event 'item-selected'
i am using this element in another custom element and when i try to add eventlistener to this element
<dom-module id="my-list">
<template is="dom-if" if="{{show}}">
<y-list list="{{list}}">
</y-list>
<hr>
</template>
</dom-module>
Polymer({
is: 'my-list',
properties: {
show: {
type:Boolean,
value:function() {
return false
}
},
list: {
type:Array,
value:[]
}
},
ready: function(){
},
attached: function(){
this.querySelector('y-list').addEventListener('item-selected', function(e){
console.log(e.detail);
}
});
i am getting the error
Cannot read property 'addEventListener' of null
but if i remove dom-if
condition or use hidden$
i am able to find the element and add the eventlistener and listen to item-selected
event
I know that attached is called after ready so i am adding event listener in attached but i am unable to find the element even if i set the show
attribute to true
for <my-list>