Javascript Angularjs可以';t访问函数外部的变量
我无法访问“apiURL”,我在控制台日志中遇到此错误 angular.min.js:113获取404(未找到) JS:Javascript Angularjs可以';t访问函数外部的变量,javascript,angularjs,Javascript,Angularjs,我无法访问“apiURL”,我在控制台日志中遇到此错误 angular.min.js:113获取404(未找到) JS: $scope.searchFunction=function(){ 对于(变量i=0;i
$scope.searchFunction=function(){
对于(变量i=0;i<$scope.allTheme.length;i++){
如果($scope.selected==$scope.allTheme[i].THEMENAME){
$scope.selectedTheme=$scope.allTheme[i].QUERYNAME;
阿皮乌尔https://developers.onemap.sg/publicapi/themeapi/retrieveTheme?queryName=“+$scope.selectedTheme”+
(token)token(token)token(token)token(token)token(token)token(token)token(token)token(token)token(token)token(token)token(token)EJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ迎战Pt8J7qfMkl0RbVDse84tD5rRhwG7d7LGr9i6xQ';
}
}
}
$http.get('apirl')。然后(函数(响应){
$scope.apireult=response.data.SrchResults;
$scope.apireult.splice(0,1);
})
您将APIRL作为字符串传递$http.get('APIRL')
$scope.searchFunction=function(){
对于(变量i=0;i<$scope.allTheme.length;i++){
如果($scope.selected==$scope.allTheme[i].THEMENAME){
$scope.selectedTheme=$scope.allTheme[i].QUERYNAME;
让我们来看看https://developers.onemap.sg/publicapi/themeapi/retrieveTheme?queryName=“+$scope.selectedTheme”+
(token)token(token)token(token)token(token)token(token)token(token)token(token)token(token)token(token)token(token)token(token)EJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ迎战Pt8J7qfMkl0RbVDse84tD5rRhwG7d7LGr9i6xQ';
}
}
}
$http.get(apirl).then(函数(响应){
$scope.apireult=response.data.SrchResults;
$scope.apireult.splice(0,1);
})
传递变量,而不是字符串:$http.get(apirl)
$scope.searchFunction = function() {
for (var i = 0; i < $scope.allTheme.length; i++) {
if ($scope.selected == $scope.allTheme[i].THEMENAME) {
$scope.selectedTheme = $scope.allTheme[i].QUERYNAME;
let apiURL = 'https://developers.onemap.sg/publicapi/themeapi/retrieveTheme?queryName=' + $scope.selectedTheme +
'&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMsInVzZXJfaWQiOjMsImVtYWlsIjoicHVibGljQXBpUm9sZUBzbGEuZ292LnNnIiwiZm9yZXZlciI6ZmFsc2UsImlzcyI6Imh0dHA6XC9cL29tMi5kZmUub25lbWFwLnNnXC9hcGlcL3YyXC91c2VyXC9zZXNzaW9uIiwiaWF0IjoxNTQwNDU0NTQ2LCJleHAiOjE1NDA4ODY1NDYsIm5iZiI6MTU0MDQ1NDU0NiwianRpIjoiOWNlOGU3MGZmZTc3MTk5NjY1YjE0Mzc5MzZkN2IzNTIifQ.Is-oNPt8J7qfMkl0RbVDse84tD5rRhwG7d7LGr9i6xQ';
}
}
}
$http.get(apiURL).then(function(response) {
$scope.apiResult = response.data.SrchResults;
$scope.apiResult.splice(0, 1);
})