Angular2 - Leaflet-Event上的Fire事件

时间:2016-07-21 23:39:23

标签: angularjs typescript angular leaflet

我正试图用我的Ionic 2应用程序使用Angular 2 TS来实现Leaflet。我想在点击Leaflet-pin时发出 pinClicked -event。这该怎么做?在Angular1 $ scope中。$ apply是解决方案......

private refreshMarkers() {
    L.marker([40.731253, -73.996139])
      .addTo(this.map)
      .on('click', function() { alert('JA'); } );
  }

  private pinWasClicked() {
    this.pinClicked.emit('');
  }

1 个答案:

答案 0 :(得分:1)

试试这个

private refreshMarkers() {
let marker=L.marker([40.731253, -73.996139]);
  marker.addTo(this.map);
  marker.on('click', 
             (e)=>
             {this.pinWasCliscked(e)} );
}
private pinWasClicked(e) {
console.log(e);
this.pinClicked.emit('');
}