为什么我得到错误:http.get不是一个函数

时间:2015-11-15 10:04:14

标签: 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不是函数。

知道我为什么会收到错误吗?

1 个答案:

答案 0 :(得分:2)

在控制器函数中使用依赖项时,不应更改依赖关系序列。

<强>代码

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

相关问题