AngularJS $http.get returns undefined and $http() is not a function(AngularJS $http.get 返回 undefined 并且 $http() 不是函数)
问题描述
我正在构建一个应用程序以在 AngularJS 中动态加载和显示数据库中的数据,但是当我尝试访问我的 API(使用 $http() 或 $http.get())时,我收到了错误.$http.get() error: TypeError: undefined is not a function
, $http() error: TypeError: object is not a function
I'm building an app to dynamically load and display data from a database in AngularJS, but when I try to access my API (using either $http() or $http.get()), I receive errrors.
$http.get() error: TypeError: undefined is not a function
, $http() error: TypeError: object is not a function
此特定错误发生在动态加载导航选项卡的代码中.
This specific error occurs in the code to dynamically load navigation tabs.
CoffeeScript 中的代码:
The code for both in 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
]
有人看到我在这里做错了吗?
Does anyone see what I'm doing wrong here?
推荐答案
当使用数组表示法注入依赖时,参数的顺序很重要:
When using the array notation for injecting dependencies, the order of the arguments is important:
在您的代码中:
['$routeParams',
'$scope',
'$http',
function ($http, $scope, $routeParams) {
// $http argument ==> $routeParams
// $scope argument ==> $scope (by coincidence)
// $routeParams argument ==> $http
}
所以,基本上,您正在执行 $routeParams.get()
,但 $routeParams
没有方法 get()
(也没有它本身就是一个函数).
So, basically, you are doing $routeParams.get()
, but $routeParams
has no method get()
(nor is it a function itself).
这篇关于AngularJS $http.get 返回 undefined 并且 $http() 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:AngularJS $http.get 返回 undefined 并且 $http() 不是函数


- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01