AngularJS $ http.get返回undefined和$ HTTP()不是一个函数 [英] AngularJS $http.get returns undefined and $http() is not a function

查看:385
本文介绍了AngularJS $ http.get返回undefined和$ HTTP()不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个应用程序来动态地从数据库中AngularJS加载和显示数据,但是当我尝试访问我的API(使用HTTP $()或$ http.get()),我收到errrors。
$ http.get()错误:类型错误:未定义不是一个函数,$ HTTP()错误:类型错误:对象不是一个函数

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

在code会出现此特定错误动态加载导航选项卡。

This specific error occurs in the code to dynamically load navigation tabs.

在CoffeeScript中的code为:

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:

在您的code:

['$routeParams',
 '$scope',
 '$http',
 function ($http, $scope, $routeParams)  {
    // $http argument        ==> $routeParams
    // $scope argument       ==> $scope (by coincidence)
    // $routeParams argument ==> $http
}

所以,基本上,你正在做的 $ routeParams.get(),但 $ routeParams 没有方法获得()(也不是函数本身)。

So, basically, you are doing $routeParams.get(), but $routeParams has no method get() (nor is it a function itself).

这篇关于AngularJS $ http.get返回undefined和$ HTTP()不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆