即使在注入http之后,Uncaught TypeError: Cannot read property 'ge

Even after injection of http, Uncaught TypeError: Cannot read property 'get' of undefined

本文关键字:property read Cannot ge TypeError 注入 http 之后 Uncaught      更新时间:2023-09-26

我有以下简单的代码,但我得到的错误,即使$http注入:

angular.module('bizapp')
.controller('SalesCtrl', ['$scope', '$http', GetSalesInvoices]);
function GetSalesInvoices($scope, $http) {
    $scope.invoices = [];
    $scope.refresh = function($scope, $http) {
        var url = "https://foo.ic/api/salesinvoice/SalesInvoices";
        $http.get(url)
          .success(function(data) {
            $scope.invoices = data.d.results;
          })
          .error(function(){
              console.log('opss')
          })
          .finally(function() {
           $scope.$broadcast('scroll.refreshComplete');
         });
    }
}

Uncaught TypeError: Cannot read property 'get' of undefined我错过了什么?

您的控制器中已经有$scope$http,因此您不需要将它们作为参数传递给功能refresh。把

$scope.refresh = function($scope, $http) {

$scope.refresh = function() {

应该都能正常运行