简体   繁体   English

解析错误:意外的令牌

[英]Parsing Error: Unexpected token

I am working on a MEAN STACK application and I am trying to create a AngularJS factory that makes use of $http . 我正在开发MEAN STACK应用程序,并且试图创建一个使用$httpAngularJS工厂。 Below is the code of my gMapService.js . 以下是我的gMapService.js的代码。

gMapService.js gMapService.js

var myApp = myApp.factory("gMapService",['$http', function($http){
var urlBase = "https://mymapservice.com/api/function/json";
    return {
        function1: function (arg) {
            return{
                $http.get(urlBase, {
                    cache: true,
                    headers:{
                      "Content-Type":"application/json"
                    },
                    params:{
                        address:arg
                    }
                })
                .then(function (resp) { 
                    return resp.data; 
                });   
        }
    };   
}]);

I have used a similar code in the past and I never had an issue with it until now where my code editor is signaling this error in 我过去曾经使用过类似的代码,但直到现在我的代码编辑器在发出此错误消息时都没有遇到任何问题

line 6: Parsing Error: Unexpected token . 第6行:解析错误:意外的令牌。

Please tell me what i am doing wrong here. 请告诉我我在这里做错了。 I am using angular 1.5.8 我正在使用angular 1.5.8

You have a misguided } character after the declaration of function1 , just remove that character: function1的声明之后,您有一个误导的}字符,只需删除该字符即可:

var myApp = myApp.factory("gMapService", ["$http", function($http) {
    var urlBase = "https://mymapservice.com/api/function/json";
    return {
        function1: function(arg) {
            return $http.get(urlBase, {
                cache: true,
                headers: {
                    "Content-Type": "application/json"
                },
                params: {
                    address: arg
                }
            })
                .then(function(resp) {
                    return resp.data;
                });
        }
    }
}]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM