Click on link inside leaflet bindpopup is not working

时间:2019-03-19 14:48:09

标签: javascript angular ionic-framework leaflet

I'm trying to add a link in my leaflet marker bindpopup and it's not working, The click do nothing, really nothing, no event...:

for (var i = 0; i < this.array.length; i++) {
    let arrayDetails = this.array[i];
    var popupLink='<a (click)="console.log("toto")">See more information</a>';
    var marker = new leaflet.Marker([this.array[i]["lat"],this.array[i]["lng"]], {icon: orangeIcon})
    .addTo(this.map)
    .bindPopup(popupLink);
}

I tried with function as well and it's not working. Do you have any idea? (The link should push to a detail page.)

1 个答案:

答案 0 :(得分:0)

您必须对console.log()中的引号进行转义,尝试这种方式:

for (var i = 0; i < this.array.length; i++) {
    let arrayDetails = this.array[i];
    var popupLink='<a onclick="console.log(\'toto\')">See more information</a>';
    var marker = new leaflet.Marker([this.array[i]["lat"],this.array[i]["lng"]], {icon: orangeIcon})
    .addTo(this.map)
    .bindPopup(popupLink);
}

编辑:修复点击方法的名称