2015-11-15 98 views
1

我有這樣的代碼:爲什麼我得到錯誤:http.get不是一個函數

(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。進入不是一個功能。

任何想法,爲什麼我得到錯誤?

回答

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

相關問題