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
- 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
1 Answer
Reset to default 3You 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
评论列表(0条)