Typescript leaflet marker popup with clickable button

Mustafa Ülker
Oct 22, 2020

write in map.ts

popupOptions = { className: "customPopup" };this.popupMessage='<button class="postGim">Mesaj Yolla</button> ';setMyCoords() {this.geolocation.getCurrentPosition().then((resp) => {this.myY_coord = resp.coords.latitudethis.myX_coord = resp.coords.longitude}).catch((error) => {console.log(this.en_error_getting_location, error);});
this.markerlat = this.myY_coord;this.markerlng = this.myX_coord;addmarker(){Leaflet.marker([this.markerlat, this.markerlng]).addTo(this.map).bindPopup(this.popupMessage, this.popupOptions).on("popupopen", (a) => {var popUp = a.target.getPopup()popUp.getElement().querySelector(".postGim").addEventListener("click", e => {this.buttonAction();});}).openPopup();}buttonAction() {console.log("buttonAction() cagrildi");}

We are writing the button as popup message but you know typescript cannot do anything in it.

Catch the class in javascript named postGIM here and return to typescript.:)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response