javascript - Parsing Error: Unexpected token - Stack Overflow

I am working on a MEAN STACK application and I am trying to create a AngularJS factory that makes use o

I am working on a MEAN STACK application and I am trying to create a AngularJS factory that makes use of $http. Below is the code of my gMapService.js.

gMapService.js

var myApp = myApp.factory("gMapService",['$http', function($http){
var urlBase = "";
    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 .

Please tell me what i am doing wrong here. I am using angular 1.5.8

I am working on a MEAN STACK application and I am trying to create a AngularJS factory that makes use of $http. Below is the code of my gMapService.js.

gMapService.js

var myApp = myApp.factory("gMapService",['$http', function($http){
var urlBase = "https://mymapservice./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 .

Please tell me what i am doing wrong here. I am using angular 1.5.8

Share Improve this question edited Oct 26, 2016 at 10:56 AllJs asked Oct 26, 2016 at 6:26 AllJsAllJs 1,8104 gold badges29 silver badges51 bronze badges 4
  • Which line no 6 ? – RIYAJ KHAN Commented Oct 26, 2016 at 6:28
  • in gMapService.js – AllJs Commented Oct 26, 2016 at 6:29
  • buddy,please copy your response and check in any json validation tool for json is correct or not – RIYAJ KHAN Commented Oct 26, 2016 at 6:33
  • I tried that but my concern is that it doesn't make sense to me. i have used similar code in the past and it works. Please let me know what is wrong here. – AllJs Commented Oct 26, 2016 at 6:34
Add a ment  | 

1 Answer 1

Reset to default 3

You have a misguided } character after the declaration of function1, just remove that character:

var myApp = myApp.factory("gMapService", ["$http", function($http) {
    var urlBase = "https://mymapservice./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;
                });
        }
    }
}]);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744236607a4564500.html

相关推荐

  • javascript - Parsing Error: Unexpected token - Stack Overflow

    I am working on a MEAN STACK application and I am trying to create a AngularJS factory that makes use o

    8天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信