Javascript 即使在注入http之后,uncaughttypeerror:cannotreadproperty';获取';未定义的
我有以下简单代码,但即使注入了$http,也会出现错误: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
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() {