我有一个点击事件,我通过<a>
标签附加到了Google地图信息窗口。但是,即使它说它已被激活,它也不会触发该功能。
我尝试添加ng-app=""
和ng-controler=""
失败
.controller('mainCtrl', function($scope, $rootScope, $stateParams,
uiGmapGoogleMapApi, $cordovaGeolocation, $state, $firebase,
$ionicModal) {
var createMap = function(position){
angular.extend($scope, {
map: {center: {latitude: position.coords.latitude,longitude:position.coords.longitude},
zoom: 13,
markers: markersarray,
options: {
// This is an example of a variable that cannot be placed outside of uiGmapGooogleMapApi without forcing of calling the google.map helper outside of the function
streetViewControl: false,
mapTypeControl: false,
scaleControl: false,
rotateControl: false,
zoomControl: false
},
events: {
click: function (map, eventName, originalEventArgs) {
var e = originalEventArgs[0];
Marker_Latt = e.latLng.lat();
Marker_Long = e.latLng.lng();
$scope.openModal();
}
},
markersEvents: {
click: function(marker, eventName, model, args) {
for(var i = 0; i < markersarray.length; i++){
if(markersarray[i].id === marker.key){
var content = '';
content += '<div ng-app="main" ng-controller="mainCtrl"><p>Added By: <a style="cursor: pointer;" [routerLink]="" (click)="navigatetoUser()">'+markersarray[i].username+'</a></p>';
content += '<p>Added On: ' + markersarray[i].date.toString() + "</p></div>";
navigateUserID = markersarray[i].userid;
createWindow(marker.get('map'), marker, content);
break;
}
}
},
dblclick:function(marker, eventName, model, args) {
console.log("double click!" + marker);
}
},
}
} );
};
$scope.navigatetoUser = function(){
console.log("button clicked..");
//$scope.data.selectedUserID = navigateUserID;
//$state.go('userProfile', $scope.data);
};
function createWindow(map, marker, content){
var infowindow = new google.maps.InfoWindow({
content: content
});
infowindow.open(map, marker);
}
});
navigatetoUser()函数未触发,我看不到任何错误
原始代码:“''
<ui-gmap-window isiconvisibleonclick="true">
<p> {{CurrentMakerTitle}}
<a href="" ng-click="$root.navigatetoUser()">
{{CurrentMakerUserName}}
</a>
<br>{{CurrentMakerDateAdded}}
</p>
</ui-gmap-window>
</ui-gmap-marker>
'''我将其更改为infowindow,因为多个窗口显示了最终点击信息–
答案 0 :(得分:0)
谢谢所有发表评论的人,我设法做到以下几点:
click: function(marker, eventName, model, args) {
for(var i = 0; i < markersarray.length; i++){
if(markersarray[i].id === marker.key){
navigateUserID = markersarray[i].userid;
var content = '<p>Added By: <a id="Info_'+marker.key+'" style="cursor: pointer;" [routerLink]="">'+markersarray[i].username+'</a></p>'
content += '<p>Added On: ' + markersarray[i].date.toString() + "</p>";
createWindow(marker.get('map'), marker, content, marker.key);**
break;
}
}
}
function createWindow(map, marker, content, key){
var infowindow = new google.maps.InfoWindow({
content: content
});
infowindow.open(map, marker);
google.maps.event.addListener(infowindow, 'domready', function() {
var mapDiv = document.getElementById('Info_'+key+'');
google.maps.event.addDomListener(mapDiv, 'click', function() {
navigatetoUser();
});
});
}