【问题标题】:why I get error: http.get is not a function为什么我收到错误:http.get 不是函数
【发布时间】:2017-04-11 20:19:38
【问题描述】:

我有这个代码:

(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 不是函数。

知道我为什么会出错吗?

【问题讨论】:

    标签: javascript angularjs angularjs-http


    【解决方案1】:

    在控制器函数中使用依赖项时不应更改依赖项顺序。

    代码

    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

    【讨论】:

      猜你喜欢
      • 2019-08-19
      • 2020-02-04
      • 2019-10-14
      • 2023-01-24
      • 2017-12-20
      • 2011-01-03
      • 2022-08-03
      • 1970-01-01
      • 2017-01-10
      相关资源
      最近更新 更多