Javascript 角度标记误差

Javascript 角度标记误差,javascript,angularjs,html,leaflet,angular-leaflet-directive,Javascript,Angularjs,Html,Leaflet,Angular Leaflet Directive,我突然发现了这一点,这让我无法正确使用我的传单地图。每次我点击地图,都会在相同的坐标上添加一个标记。当我尝试使用函数删除标记时,它会清空标记数组,但是标记在地图上仍然可见。发生什么事了 Error: [$parse:syntax] Syntax Error: Token '.0' is an unexpected token at column 8 of the expression [markers.0] starting at [.0]. http://errors.angularj

我突然发现了这一点,这让我无法正确使用我的传单地图。每次我点击地图,都会在相同的坐标上添加一个标记。当我尝试使用函数删除标记时,它会清空标记数组,但是标记在地图上仍然可见。发生什么事了

    Error: [$parse:syntax] Syntax Error: Token '.0' is an unexpected token at column 8 of the expression [markers.0] starting at [.0].
http://errors.angularjs.org/1.4.8/$parse/syntax?p0=.0&p1=is%20an%20unexpected%20token&p2=8&p3=markers.0&p4=.0
    at angular.js:68
    at Object.AST.throwError (angular.js:13100)
    at Object.AST.ast (angular.js:12870)
    at Object.ASTCompiler.compile (angular.js:13319)
    at Parser.parse (angular.js:14189)
    at $parse (angular.js:14291)
    at Scope.$watch (angular.js:15482)
    at createMarker (angular-leaflet-directive.js:1016)
    at Object.fn (angular-leaflet-directive.js:795)
    at Scope.$digest (angular.js:15896)
如果有帮助,这里有一些代码

Controller.js:

$scope.location = {lat: 8.812354, lng: -11.887342};

            $scope.center = {
                lat: 8.812354,
                lng: -11.887342,
                zoom: 8
            };

            $scope.markers = [];
            $scope.markers.push({
                lat: 8.812354,
                lng: -11.667342,
                message: "hehe"
            });

    //This one is added to the array, but doesn't show up in the map
            $scope.markers.push({
                lat: 7.812354,
                lng: -10.667342,
                message: "WOOP"
            });

$scope.$on("leafletDirectiveMap.click", function (event, args) {

            var leafEvent = args.leafletEvent;
            console.log('Ctrl3 adding marker at lat=' + leafEvent.latlng.lat + ', lng=' + leafEvent.latlng.lng);
            $scope.location.lng = leafEvent.latlng.lng;
            $scope.location.lat = leafEvent.latlng.lat;

            $scope.markers.push({
                lat: leafEvent.latlng.lat,
                lng: leafEvent.latlng.lng,
                message: "My Added Marker"
            });
        });
HTML:

请注意,$scope.markers是,而不是数组。该指令试图枚举markers对象的属性,但在数组具有的数字属性上失败

将$scope.markers更改为{},并在某个键处向对象添加新标记,而不是将其推送到数组中,例如:

$scope.markers = {};

// ...

var idx = 0;
$scope.$on("leafletDirectiveMap.click", function (event, args) {
    idx += 1;

    $scope.markers['marker' + idx] = {
        // ...
    };
});

一些代码可能有助于现在添加一些代码。如果需要更多,请告诉我!
$scope.markers = {};

// ...

var idx = 0;
$scope.$on("leafletDirectiveMap.click", function (event, args) {
    idx += 1;

    $scope.markers['marker' + idx] = {
        // ...
    };
});