角令牌错误 [英] Angular Token Error

查看:279
本文介绍了角令牌错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 错误:[$解析:语法]语法错误:令牌'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 ; /单张>


解决方案

注意 $ scope.markers 是<一个href=\"https://github.com/tombatossals/angular-leaflet-directive/blob/master/doc/markers-attribute.md\"相对=nofollow>应该是一个对象,而不是一个数组。该指令是试图枚举标记对象的属性,未能在该阵列具有数字属性。

更改 $ 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] = {
        // ...
    };
});

这篇关于角令牌错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆