AngularJS - Google maps ui-sref inside marker

Hi, I have google maps in angular and I'm trying to make a custom marker.content button to go to another route. I install merkers in a service like this

this.setMarker = function (item, map) {
    var position = new google.maps.LatLng(item.loc[1], item.loc[0]);
    bounds.extend(position);

    var marker = new google.maps.Marker({
        map: map,
        position: position,
        title: item.name,
        icon: iconBase + 'basic_pin.png'
    });

    marker.content = '<div class="infoWindowContent">' +
    '<div class="author">' + item.user.name + '</div>' +
    '<div class="horizontal">' +
    '<dl>' +
    '<dt>created:</dt>' +
    '<dd class="ng-binding">'  + $filter('dateFormat')(item.created_at)  +'</dd>' +
    '<dt>tracks:</dt>' +
    '<dd class="ng-binding">' + item.tracks.length + '</dd>' +
    '<dt>type:</dt>' +
    '<dd class="ng-binding">' + utilsFactory.getPlaylistType(item.settings.is_private,item.settings.is_yoobox,item.settings.is_locked) + '</dd>' +
    '</dl>' +
    '</div>' +
    '<div class="pink_button enter-play">                ' +
    '<a ui-sref="detailSite({playlistID: item._id})" ng-show="false">play</a>' +
    '</div>'+
    '</div>';

    return marker;
};

The problem is that ui-sref does not work like other angular directives. Does anyone know a solution for this?

+4
source share
1 answer

you need to use the $ compilation service.

 marker.content = '<div class="infoWindowContent">' +
    '<div class="author">' + item.user.name + '</div>' +
    '<div class="horizontal">' +
    '<dl>' +
    '<dt>created:</dt>' +
    '<dd class="ng-binding">'  + $filter('dateFormat')(item.created_at)  +'</dd>' +
    '<dt>tracks:</dt>' +
    '<dd class="ng-binding">' + item.tracks.length + '</dd>' +
    '<dt>type:</dt>' +
    '<dd class="ng-binding">' + utilsFactory.getPlaylistType(item.settings.is_private,item.settings.is_yoobox,item.settings.is_locked) + '</dd>' +
    '</dl>' +
    '</div>' +
    '<div class="pink_button enter-play">                ' +
    '<a ui-sref="detailSite({playlistID: item._id})" ng-show="false">play</a>' +
    '</div>'+
    '</div>';

    var compiledContent = $compile(marker)($scope);

    return compiledContent[0];

The documentation is here $ compile

+1
source

Source: https://habr.com/ru/post/1599754/


All Articles