How To Write Onclick Action From Infowindow Content In Angular 4
i am working on google maps in angular 4 project i need a click event inside the infowindow,how to write it??? i have tried with the following code but the name is undefined.i have
Solution 1:
To call a function you defined in you angular component from the google maps infowindow you simply need to do the following things:
- in your constructor import NgZone
constructor(public _ngZone: NgZone) {}
- inside the function ngOnInit() save a reference of your component and NgZone to the window context
window['angularComponentRef'] = { component: this, zone: this._ngZone };
- From your infowindow html call your function like this
const markerInfoWindow = new google.maps.InfoWindow({
content: <divonclick="window.angularComponentRef.zone.run(() =>{window.angularComponentRef.component.yourFunction()})"></div>,
});
Happy coding
Post a Comment for "How To Write Onclick Action From Infowindow Content In Angular 4"