我正在使用 Angular.JS 和 Leaflet.JS 作为我所在位置的地图,该地图具有绑定到它们的弹出窗口的地图标记。我需要使用一个带有两个不同图标(一个在下面的代码中显示)的跨度,您可以单击它们来调用不同的函数,并在满足某些条件时使用 ng-class 来更改类。这是我的代码:
var marker = L.marker([51.5, -0.09], {icon: blueIcon}).bindPopup('<br><span ng-class="thumbsUpClass(' + hotelsSelectedDates[i]['hotels'][s] + ')" ng-click="addChoice(' + hotelsSelectedDates[i]['hotels'][s] + ',' + hotels + ')"><span class="popup-container"><span class="icon-stack thumbs-up-stack"><i class="icon-sign-blank icon-stack-base"></i><i class="icon-thumbs-up"></i></span></span></span>');
但是,当我检查元素时,我得到了这个:
<span ng-class="thumbsUpClass([object Object])" ng-click="addChoice([object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object])"><span class="popup-container"><span class="icon-stack thumbs-up-stack"><i class="icon-sign-blank icon-stack-base"></i><i class="icon-thumbs-up"></i></span></span></span>
ng-click 应该向该函数发送特定对象和对象数组,但是当我单击图标时没有任何反应。在我的研究中,我发现弹出窗口阻止了事件传播(更多信息,但我不确定如何覆盖它或修复它以使其与角度一起使用。有人知道如何实现这一点吗?
更新:
由于 ng-click/class 评估一个字符串,我将变量固定为:
$scope.item = hotelsSelectedDates[i]['hotels'][s]
$scope.set = hotels
var marker = L.marker([51.5, -0.09], {icon: blueIcon}).bindPopup('<br><span ng-class="thumbsUpClass(item)" ng-click="addChoice(item,set)"><span class="popup-container"><span class="icon-stack thumbs-up-stack"><i class="icon-sign-blank icon-stack-base"></i><i class="icon-thumbs-up"></i></span></span></span>');
html 然后正确显示:
<span ng-class="thumbsUpClass(item)" ng-click="addChoice(item,set)"><span class="popup-container"><span class="icon-stack thumbs-up-stack"><i class="icon-sign-blank icon-stack-base"></i><i class="icon-thumbs-up"></i></span></span></span>
但是,当我单击该图标时,什么也没有发生,并且看起来没有调用函数。任何人都知道为什么会发生这种情况?