Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 即使在注入http之后,uncaughttypeerror:cannotreadproperty';获取';未定义的_Javascript_Angularjs - Fatal编程技术网

Javascript 即使在注入http之后,uncaughttypeerror:cannotreadproperty';获取';未定义的

Javascript 即使在注入http之后,uncaughttypeerror:cannotreadproperty';获取';未定义的,javascript,angularjs,Javascript,Angularjs,我有以下简单代码,但即使注入了$http,也会出现错误: angular.module('bizapp') .controller('SalesCtrl', ['$scope', '$http', GetSalesInvoices]); function GetSalesInvoices($scope, $http) { $scope.invoices = []; $scope.refresh = function($scope, $http) { var ur

我有以下简单代码,但即使注入了$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');
         });
    }
}
未捕获的TypeError:无法读取未定义的属性“get”
我缺少什么?

控制器中已经有
$scope
$http
,因此不需要将它们作为参数传递给函数
刷新
。改变

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

它应该都能工作

闭包(本例中为刷新)是一个内部函数,可以访问外部(本例中为控制器)函数的变量。
$scope.refresh = function() {