我正在开发 MEAN STACK 应用程序,并尝试创建一个使用 $http
的 AngularJS
工厂。下面是我的 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;
});
}
};
}]);
我过去使用过类似的代码,直到现在我的代码编辑器在
中发出此错误信号为止,我从未遇到过任何问题line 6: Parsing Error: Unexpected token .
请告诉我我在这里做错了什么。我正在使用 Angular 1.5.8
最佳答案
在 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;
});
}
}
}]);
关于javascript - 解析错误: Unexpected token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40255143/