dom-change
event object e in Polymer.dom(e).localTarget
gives me <template is="dom-if"
as it should. But how do I access the child <div id="uploadedImage1"
? firstChild
and firstElementChild
are null.
<template is="dom-if" if="[[uploadedImage1]]">
<div id="uploadedImage1" class="row-image horizontal layout">
foo
</div>
</template>
I thought maybe I need to do another query off of the localTarget object but no success:
this.$['images-container'].addEventListener('dom-change', (e)=> {
var bob = Polymer.dom(e).localTarget;
var sue = Polymer.dom(bob).querySelector('div')
console.log(sue);
});
I also tried these to no success:
this.$['images-container'].addEventListener('dom-change', (e)=> {
var bob = Polymer.dom(e).localTarget;
var sue = this.queryEffectiveChildren(bob);
console.log(sue);
});
this.$['images-container'].addEventListener('dom-change', (e)=> {
var bob = Polymer.dom(e).localTarget;
var sue = bob.getEffectiveChildNodes();
console.log(sue);
});
}
From children length documentation example, even Polymer.dom(this).children.length
returned 0:
<dom-module id="image-uploader">
<template>
<style include="iron-flex iron-flex-factors iron-flex-alignment">
<div id="images-container" class="horizontal layout center wrap">
<div hidden="[[uploadedImage1]]" class="layout vertical center-center">
<div class="row-image horizontal layout">
<input
type="file"
name="file"
data-uploaded="uploadedImage1"
id="image1"
accept="image/jpeg"
class="inputfile" />
<label
for="image1"
id="image1"
class="image-show horizontal layout center center-justified">
<iron-icon icon="add" prefix></iron-icon>
Upload Image
</label>
</div>
<i>*Main Image</i>
</div>
<template is="dom-if" id="foo" if="[[uploadedImage1]]">
<div id="uploadedImage1">
foo
</div>
</template>
</div>
</template>
<script>
Polymer({
is: 'image-uploader',
properties: {
uploadedImage1: {
type: Boolean,
value: false
}
},
ready: function(e) {
console.log(Polymer.dom(this).children.length);