0

我正在使用 angularjs UI-map,我从 firebase 循环数据。到目前为止一切顺利,但是当我单击标记时,它总是显示最后的查询数据。这是狙击手代码

在 html 中

    <!-- Setup Marker -->
    <div    ng-repeat="marker in markers"
            ui-map-marker="markers[$index]"
            ui-event="{'map-click': 'showMarkerInfo(marker)'}">
    </div>

    <!-- Setup Marker Info Window -->
    <div ui-map-info-window="infoWindow">
        <div>Marker - <input ng-model="full_name"></div>
        <div>Message</div>
    </div>

在 JS 中

firebaseAuth.firebaseRef.child('/human/').on('child_added', function(snapshot) {
    $scope.users = snapshot.val();
    $scope.latLng = new google.maps.LatLng($scope.users.lat, $scope.users.lng);
    $scope.markers.push(new google.maps.Marker({
        map: $scope.map,
        position: $scope.latLng
    }));

});


        $scope.showMarkerInfo = function(marker) {
            $scope.currentMarkerLat = $scope.users.full_name;
            $scope.infoWindow.open($scope.map, marker);
            console.log(marker);
        };
4

1 回答 1

0

我还没有尝试过 angular-ui,但是这个问题看起来和“ Javascript臭名昭著的循环问题”一样,所以你可能想试试:

ui-event="{'map-click': 'showMarkerInfo(markers[$index])'}"

但是,我想它会遇到同样的问题,但值得一试。

于 2013-06-14T06:05:12.860 回答