我想从文件 driverStandings.json 加载 json(您可以看到它留在图像的结构中)。我使用服务 API 来加载此数据。我使用以下代码(位于图像中)。
当我编译时,我没有得到我的驱动程序列表,我得到以下错误列表
TypeError: url.replace is not a function
at angular.js:8557
at sendReq (angular.js:8426)
at $get.serverRequest (angular.js:8146)
at deferred.promise.then.wrappedCallback (angular.js:11682)
at deferred.promise.then.wrappedCallback (angular.js:11682)
at angular.js:11768
at Scope.$get.Scope.$eval (angular.js:12811)
at Scope.$get.Scope.$digest (angular.js:12623)
at Scope.$get.Scope.$apply (angular.js:12915)
at done (angular.js:8450)
什么是类型错误以及我做错了什么?
最佳答案
您不想使用 jsonp
作为静态 json 资源的方法,并且您正在嵌套另一个 $http
调用作为外部资源的 url
只需使用内部 $http 并去掉外部的
FAPI.getDrivers = function(id){
return $http.get( ... path to json file ...)
}
关于javascript - AngularJS 从 services.js 中的文件加载 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32160673/