角令牌错误令牌、错误

2023-09-14 00:15:02 作者:独霸天下

我得到这个突然的,而这并不让我正确地使用我的单张地图。每次我点击地图上的标记被添加到同一坐标。当我尝试用一​​个函数删除标记,它清空标记阵列,但是标志仍然显示在地图上。这是怎么回事?

 错误:[$解析:语法]语法错误:令牌'0.0'位于前pression [markers.0] 8列一个意外标记开始[ 0.0。http://errors.angularjs.org/1.4.8/$parse/syntax?p0=.0&p1=is%20an%20unexpected%20token&p2=8&p3=markers.0&p4=.0    在angular.js:68    在Object.AST.throwError(angular.js:13100)    在Object.AST.ast(angular.js:12870)    在Object.ASTCompiler.compile(angular.js:13319)    在Parser.parse(angular.js:14189)    在$解析(angular.js:14291)    在范围$腕表(angular.js:15482)。    在createMarker(角单张-directive.js:1016)    在Object.fn(角单张-directive.js:795)    。在范围$消化(angular.js:15896) 

下面是一些code。如果它帮助。

Controller.js:

  $ scope.location = {纬度:8.812354,经度:-11.887342};            $ scope.center = {                纬度:8.812354,                LNG:-11.887342,                变焦:8            };            $ scope.markers = [];            $ scope.markers.push({                纬度:8.812354,                LNG:-11.667342,                消息:嘻嘻            });    //这其中被添加到阵列中,但在图不显示            $ scope.markers.push({                纬度:7.812354,                LNG:-10.667342,                消息:WOOP            });$范围。在(leafletDirectiveMap.click$,功能(事件参数){            VAR leafEvent = args.leafletEvent;            的console.log(+ leafEvent.latlng.lat +'CTRL3在北纬=添加标记',LNG ='+ leafEvent.latlng.lng);            $ scope.location.lng = leafEvent.latlng.lng;            $ scope.location.lat = leafEvent.latlng.lat;            $ scope.markers.push({                纬度:leafEvent.latlng.lat,                LNG:leafEvent.latlng.lng,                消息:我添加的标记            });        }); 

HTML

 <小叶类=COL-MD-偏移4图默认值=默认标记=标记中心=中心层=层>&LT ; /单张> 
服务器直接ip登录显示令牌错误,SSL 配置动态令牌认证,令牌同步失败提示获取认证服务器配置失败或本地IP与认证服务器IP地址不匹配...

解决方案

注意 $ scope.markers 是应该是一个对象,而不是一个数组。该指令是试图枚举标记对象的属性,未能在该阵列具有数字属性。

更改 $ scope.markers {} ,并在一些关键的,而不是增加新的标记对象它ING到阵列中,例如:

  $ scope.markers = {};// ...变种IDX = 0;$范围。在(leafletDirectiveMap.click$,功能(事件参数){    IDX + = 1;    $ scope.markers ['标记'+ IDX] = {        // ...    };}); 

I am getting this all of a sudden, and It doesn't let me use my leaflet map properly. Everytime I click on the map, a marker is added to the same coordinates. When I try to remove markers with a function, it empties the markers-array, however the markers are still visible on the map. What's going on?

    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)

Here's some code if it helps.

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:

<leaflet class="col-md-offset-4 map" defaults="defaults" markers="markers" center="center" layers="layers"></leaflet>

解决方案

Note that $scope.markers is supposed to be an object, not an array. The directive is trying to enumerate the properties of the markers object and fails on the numeric properties that array has.

Change your $scope.markers to {} and add new markers to the object at some key instead of pushing it to the array, for example:

$scope.markers = {};

// ...

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

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