我能够将img url传递给模态,但无法弄清楚如何传递img.title和最终的img.context。我从API得到的响应很好,我只需要一些帮助即可将结果单击后传递给模式。我可以传递图片网址,但不能传递image.title。
下面是jquery:
\[+([a-z- A-Z]+)\]+
HTML:
<script>
$(document).ready(function () {
$(document).on("click", ".openImageDialog", function () {
var myImageId = this.id;
$(".modal-body #myImage").attr("src", myImageId);
console.log("src " + this.id)
console.log(this);
});
});
</script>
答案 0 :(得分:0)
弄清楚了。只需将数据添加到同一元素中即可。
<div *ngFor="let image of childPhotos">
<div class="gallery">
<a href="#gardenImage" data-id={{image.url}} data-title={{image.title}} class="openImageDialog thumbnail" data-toggle="modal">
<img class="img-responsive" src={{image.url}} alt={{image.title}}>
<div class="hidden" data-title={{image.title}}></div>
</a>
<div class="desc">{{image.title}}</div>
</div>
</div>
<script>
$(document).ready(function () {
$(document).on("click", ".openImageDialog", function () {
console.log(this);
var myImageId = this.id;
var myTitleId = this.title;
console.log("myTitle " + myTitleId);
$(".modal-body #myImage").attr("src", myImageId);
$(".modal-title").text(myTitleId);
console.log("src " + this.id)
console.log(this);
});
});
</script>