Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  149] [ 1]  / answers: 1 / hits: 27154  / 10 Years ago, fri, july 18, 2014, 12:00:00

I created an array of 2 images and tried to display them, but instead of the images I got the text:

object HTMLImageElement



I am sure my images are in the right directory which I am currently working with.



< template is=auto-binding>
<section flex horizontal wrap layout>

<template repeat={{item in items}}>
<my-panel>{{item}}</my-panel>
</template>

</section>




  <script>
(function() {
addEventListener('polymer-ready', function() {
var createImage = function(src, title) {
var img = new Image();
img.src = src;
img.alt = title;
img.title = title;
return img;
};


var items = [];

items.push(createImage(images/photos/1.jpeg, title1));
items.push(createImage(images/photos/2.jpeg, title2));

CoreStyle.g.items = items;

addEventListener('template-bound', function(e) {
e.target.g = CoreStyle.g;
e.target.items = items;
});
});

})();
</script>


What am I missing here?


More From » html

 Answers
9

The easiest and safest way to do this is to put the img in the template and bind the src and title attributes like this:



<template repeat={{item in items}}>
<my-panel><img src={{item.src}} alt={{item.title}} title={{item.title}}></my-panel>
</template>


Then createImage looks like this



var createImage = function(src, title) {
return {src: src, title: title};
}

[#70159] Wednesday, July 16, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devinjadong

Total Points: 711
Total Questions: 117
Total Answers: 100

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
devinjadong questions
Thu, Feb 17, 22, 00:00, 2 Years ago
Wed, Dec 8, 21, 00:00, 2 Years ago
Tue, Oct 27, 20, 00:00, 4 Years ago
Fri, Oct 18, 19, 00:00, 5 Years ago
;