我正在构建一个应用程序来动态加载和显示 AngularJS 中数据库中的数据,但是当我尝试访问我的 API(使用 $http() 或 $http.get())时,我收到错误。
$http.get() 错误:TypeError: undefined is not a function
, $http() 错误:TypeError: object is not a function
此特定错误发生在动态加载导航选项卡的代码中。
CoffeeScript 中两者的代码:
p4pControllers.controller 'navCtrl', [
'$routeParams'
'$scope'
'$http'
($http,$scope,$routeParams) ->
$http(
method:'GET'
url:'http://p4p-api.snyx.nl/tables'
).success (data) ->
$scope.tabs = data
return
return
$http.get('http://p4p-api.snyx.nl/tables').success (data) ->
$scope.tabs = data
return
return
]
有人看到我在这里做错了什么吗?
当使用数组表示法注入依赖项时,参数的顺序很重要:
在你的代码中:
['$routeParams',
'$scope',
'$http',
function ($http, $scope, $routeParams) {
// $http argument ==> $routeParams
// $scope argument ==> $scope (by coincidence)
// $routeParams argument ==> $http
}
所以,基本上,你正在做$routeParams.get()
, but $routeParams
没有方法get()
(它本身也不是一个函数)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)