javascript - 为什么我得到错误 : http. get is not a function

标签 javascript angularjs angularjs-http

我有这个代码:

(function () {
    "use strict";

    angular.module("workPlan").controller("workPlanListController", ["workPlans",
                                                                    "clients",
                                                                    "inspectionAuthority",
                                                                    "$http",
                                                                    "config",
                                                                    "workPlanServise",
                                                                    workPlanListController]);
    function workPlanListController(workPlans,
                                    clients,
                                    inspectionAuthority,
                                    workPlanServise,
                                    config,
                                    $http) {
        var self = this;

        this.workPlanList = workPlans;
        this.lookups = {
            client: clients,
            authority: inspectionAuthority
        };

        this.gridOptions = {
            expandableRowTemplate: 'app/workPlan/templates/expandableRowTemplate.tmpl.html',
            expandableRowHeight: 150,
            enableColumnMenus: false,
            enableSorting: true,
            enableFiltering: false,
            enableToopTip: true,
            enableHorizontalScrollbar: 0,
            onRegisterApi: function (gridApi) {
                gridApi.expandable.on.rowExpandedStateChanged(null, function (row) {


                    if (row.isExpanded) {
                        row.entity.subGridOptions = {

                            columnDefs: [{ name: 'Authority', field: 'authName', cellTooltip: true },
                                         { name: '# Items, field: 'items2inspect', cellTooltip: true },
                                         { name: '% Inspected, field: 'percentage', cellTooltip: true }]
                        };

                            $http.get(config.baseUrl + "api/workPlan/").success(function (result) {
                                row.entity.subGridOptions.data = result.data;
                            });

                    }
                });
            }
        }
        this.gridOptions.columnDefs = [
{ name: 'client, field: 'clientName', cellTooltip: true, headerTooltip: true },
{ name: 'sites', field: 'siteNumbers', cellTooltip: true, headerTooltip: true },
{ name: 'checkedSites', field: 'siteNumbersInspected', cellTooltip: true, headerTooltip: true }];

        this.gridOptions.data = self.workPlanList;
    }
})();

当我尝试展开行时,我得到了这一行:

$http.get

错误:$http.get 不是函数。

知道我为什么会出错吗?

最佳答案

在 Controller 函数中使用依赖项时,不应更改依赖项顺序。

代码

angular.module("workPlan").controller("workPlanListController", ["workPlans",
    "clients",
    "inspectionAuthority",
    "$http",
    "config",
    "workPlanServise",
    workPlanListController
]);

function workPlanListController(workPlans,
    clients,
    inspectionAuthority,
    $http, //<-- $http should be here, instead of placing it at the end.
    config,
    workPlanServise
) {

SO Answer here

关于javascript - 为什么我得到错误 : http. get is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33718477/

相关文章:

javascript - 使用 Yeoman 的 angular-fullstack 在 Angular MEAN 堆栈中使用 Node Mailer 和 Sendgrid 发送电子邮件

javascript - Angular 服务/ Controller 不返回 promise ?

javascript - 当用户从列表中选择时如何显示内容详细信息?

Javascript 函数未定义且语法错误?

angularjs - Angularjs 服务是单例的吗?

angularjs - PDF Javascript Blob 中的非 UTF-8 字符

c - 如何通信 AngularJS 的 $http 路由和用 C 编程开发的 API

javascript - 一键运行 2 个函数 Javascript

javascript - 如何在 jquery 中保留 'this' 的上下文

javascript - Angular 教程 : Nodejs and certificate issue