美元AngularJS http.Get返回undefined,并且$http()不是函数

AngularJS $http.get returns undefined and $http() is not a function

本文关键字:http 函数 Get AngularJS 返回 undefined 美元 并且      更新时间:2023-09-26

我正在构建一个应用程序来动态加载和显示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()(也不是它本身的函数)。