How could I call a Angular2 function from a Google Map infowindow?

后端 未结 5 1970
小鲜肉
小鲜肉 2021-02-10 17:17

Google map is integrated the javascript way and I want to call a angular2 function inside an infowindow like the following code. Take a look at infoContent for the

5条回答
  •  半阙折子戏
    2021-02-10 18:01

    I'm search a lot and found the answer:

    You must use: $compile(htmlString)(scope)

    In your example try this:

    var infoContent = '';
    
    var scope = angular.element(document.getElementById('anyElementId')).scope();
    var compiled = $compile(htmlElement)(scope);
    

    And then use:

    infowindow.setContent(compiled[0]);
    

    Wala!

提交回复
热议问题