美元AngularJS http.Get返回undefined,并且$http()不是函数
AngularJS $http.get returns undefined and $http() is not a function
我正在构建一个应用程序来动态加载和显示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()
,但$routeParams
没有方法get()
(也不是它本身的函数)。
相关文章:
- 存储$http如何从$http函数(Angularjs)外部获取可访问变量中的响应
- 如何使用(this)访问Angular 2 http rxjs catch函数中的对象属性
- AngularJs.调用$http.success中的jQuery函数
- 在http服务单元测试中使用request-js时,chai.request不是一个函数
- 返回$http内的父函数
- 如何将多个onError函数分配给promise(由angular's$http.post返回)
- 正在等待HTTP调用从函数返回结果
- AngularJS:如何获取$http结果作为函数的返回值
- $http.post undefined 不是函数
- $http.post() angularjs 响应函数未按正确的顺序执行
- 在导出函数 MEANJS 中编写 Http 请求
- Angularjs$http删除$q promise导致TypeError:对象不是函数
- Cordova Http插件:postJSON不是函数
- 在绑定到内部$http函数时运行无限摘要循环
- 如何在 javascript 函数(如 node 或表达式 HTTP 函数)中接收默认参数
- 为什么我的范围在 angularjs 和 d3js 上的$http函数中丢失了
- 为什么我可以通过添加 .success 来执行 $http 函数
- angularjs的每个http函数的响应都放在HTML的单独一行中
- 在angular js中,如何存储变量以供其他HTTP函数使用
- AngularJS $http函数在返回时总是返回undefined