I have a "paper-dialog" object in a page. I can toggle it by a button if it is not inside a "dom-repeat" loop. But if I put it in a loop, "this.$.dialog.toggle();" will then referring to null.
<template is="dom-repeat" items="{{news}}" index-as"index">
<paper-dialog id="dialog"><h3>{{item.date}}</h3></paper-dialog>
<paper-button on-tap="toggleDialog">View {{item.name}}</paper-button>
</template>
and
toggleDialog: function(e) {
this.$.dialog.toggle();
}
Any idea why "this.$.dialog" become null after placing the dialog in a loop?
this.$won't work. You have to callthis.$$which is equal toPolymer.dom(this.root).querySelector();plus, you have multiple elements with same ID which is absolutely against html standards.
So you can do something like:
and toggleDialog
you have to set some indetification (
indexattribute) , then in function you can get this attribute by callinge.target.getAttributeand the last step is to findpaper-dialogwith the same value insideindexDialogattribute by callingthis.$$('[indexDialog="'+index+'"]')