当我点击谷歌地图[$parse:语法]中的箭头图标时,谷歌地图错误



.controller('MapCtrl', [
    '$scope', '$http', '$location', '$window',
 
function ($scope, $http, $location, $window) {
    $http.get('****').success(function (data, dealers, response) {
        function initialize() {
            var serverData = data;
            $scope.locations = [];
            for (var i = 0; i < serverData.length; i++) {
                var modal = [
                data[i].Store_Name, data[i].S_Location.Latitude, data[i].S_Location.Longitude, i, 'images/arrow.svg', data[i].S_Address];
                $scope.locations.push(modal); 
            }
            console.log($scope.locations);
            //---------------------------------------------------------
            //console i am getting like this
            var locations = [
                ['nokia store', '12.971599', '77.594563', '1', 'images/arrow.svg.svg', '55a78953815356700bee698f'],
                ['samsung store', '12.9065534', '77.5774802', '2', 'images/arrow.svg.svg', '55a786d1815356700bee6982'], ];
            //----------------------------------------------------------
            var map = new google.maps.Map(document.getElementById('map'), {
                zoom: 13,
                center: new google.maps.LatLng(12.9667, 77.5667),
                mapTypeId: google.maps.MapTypeId.ROADMAP
            });
            var infowindow = new google.maps.InfoWindow();
            var marker, i;
            for (i = 0; i < $scope.locations.length; i++) {
                //console.log($scope.locations[i][1]);
                marker = new google.maps.Marker({
                    position: new google.maps.LatLng($scope.locations[i][1], $scope.locations[i][2]),
                    map: map,
                    icon: $scope.locations[i][4],
                    animation: google.maps.Animation.DROP,
                });
                google.maps.event.addListener(marker, 'click', (function (marker, i) {
                            return function() {
			//console.log($scope.locations[i][8]);
	  var compiled = $compile('<button ng-click="navigate('+$scope.locations[i][5]+')">Navigate</button>')($scope);
			var infowindow = new google.maps.InfoWindow({content: compiled[0]});
         	
          infowindow.open(map, marker);
		   $scope.$apply();
		   
        }
                })(marker, i));
            }
            $scope.map = map;
        }
        $scope.navigate(id) {
            console.log(id);
        }
    });

当我单击图标时,我在控制台中收到这样的错误

错误:[$parse:语法] 语法错误:令牌"b24782c7d354f30cda0e89"是意外的,期望从 [b24782c72c7d354f30cda0e89(] 的第 12 列开始出现 [(]。http://errors.angularjs.org/1.3.13/$parse/syntax?p0=b24782c7d354f30cda0e89&p1=is%20unexpected%2C%20expecting%20%5B(%5D&p2=12&p3=navigate(55b24782c7d354f30cda0e89(&p4=b24782c7d354f30cda0e89( 在REGEX_STRING_REGEXP (http://localhost:8100/bower_components/angular/angular.js:63:12( at Parser.throwError (http://localhost:8100/bower_components/angular/angular.js:12011:11( at Parser.consume (http://localhost:8100/bower_components/angular/angular.js:12053:12( at Parser.functionCall (http://localhost:8100/bower_components/angular/angular.js:12323:10( at Parser.primary (http://localhost:8100/bower_components/angular/angular.js:11995:24( at Parser.unary (http://localhost:8100/bower_components/angular/angular.js:12271:19( at Parser.multiplicative (http://localhost:8100/bower_components/angular/angular.js:12254:21( at Parser.additive (http://localhost:8100/bower_components/angular/angular.js:12245:21( at Parser.relational (http://localhost:8100/bower_components/angular/angular.js:12236:21( at Parser.equality (http://localhost:8100/bower_components/angular/angular.js:12227:21( (anonymous function( @ angular.js:11607$get @ angular.js:8557invokeLinkFn @ angular.js:8221nodeLinkFn @ angular.js:7729compositeLinkFn @ angular.js:7078publicLinkFn @ angular.js:6957(anonymous function( @ controllers.js:630S.trigger @ main.js:20(anonymous function( @ VM11388:37(anonymous function( @ VM11381:10L.ff @ VM11381:195L.Dk @ VM11381:195S.trigger @ main.js:20eb @ main.js:22S.trigger @ main.js:20L.Sk @ VM11381:65(匿名函数( @ main.js:21

您收到的解析错误$parse错误,因为您的locations[i][5]变量包含一个字符串,并且您在评估后直接将该字符串放入函数navigate它变得像ng-click="navigate(55a78953815356700bee698f)"因此在编译时div它在解析该div时会抛出错误,它会抛出错误。

您可以通过在该按钮内引用带有索引的范围变量来解决此问题。

法典

$compile('<button ng-click="navigate(locations['+i+'][5])">Navigate</button>')($scope);

最新更新