Closed walidaziz closed 6 years ago
EasyButton rebinds this
in the button's handler function. (see the docs)
try avoiding the use of this
:
initMap() {
var self = this; // ADD THIS
this.map = L.map('map');
L.easyButton('fa-globe', function(btn, map){
self.myMethodToCall(); // CALL AS self
}).addTo( this.map );
}
myMethodToCall () {
// this.map....
// some dynamic stuff (call current GPS position and setView)
}
if that doesn't help, share a minimal working example.
Great ! That works. Thanks
Hi, I would like to call a method defined in my angular component class from my button. But the following code give me an 'undefined function' for myMethodToCall. How could i do that ?
Thanks