Q:

Scope of ng-click on a dynamically created button not working on Google Map

I am trying to click on a button that was dynamically created when I click on the Google Map's marker by using InfoWindow, and there is nothing triggering it. This is the link that I followed. What am I missing here? Below are my code.
JS
$scope.openMap = function(test){
    console.log(test);
}

$scope.addMarker = function(location) {
    var marker = new google.maps.Marker({
        position: location,
        map: map
    });
    var contentString = 'Lat: '+location.lat+ ' lng: '+location.lng+
                        '<button ng-click="openMap("testing")">Map</button>';
    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });
    marker.addListener('click', function() {
        infowindow.open(map, marker);
    });
    markers.push(marker);
}

The function addMarker will add a new marker location on the map. This function works and as noticed, the variable contentString was added to the attribute content in infowindow. The problem is $scope.openMap is not able to be called. 

A:

You might need to compile your html and add it.Add dependency for $compile and then change code to following. 
var contentString = 'Lat: '+location.lat+ ' lng: '+location.lng+
                    '<button ng-click="openMap("testing")">Map</button>';

contentString = $compile(contentString)($scope);

Hope it will solve your problem.

