1

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.)

IvanSanchez
  • 18,272
  • 3
  • 30
  • 45
Matthieu
  • 225
  • 1
  • 3
  • 16

1 Answers1

0

You have to escape quotes in console.log(), try this way :

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);
}

EDIT : Fix click method name

  • Thank you very much, yes it works. I guess the "click" syntax is specific ionic thats why if I want to onclick to function for example : onclick="test(arrayDetails)", I get an error : Uncaught ReferenceError: test is not defined... Do you have any idea? – Matthieu Mar 19 '19 at 16:10
  • I don't understand where is your error ? When you click on the link you have this message `Uncaught ReferenceError: test is not defined ` ? If that's so you have to verified if the `test` function exists in your app – Sébastien Bousquet Mar 19 '19 at 16:39