gpt4 book ai didi

javascript - 即使在注入(inject) http 之后,Uncaught TypeError : Cannot read property 'get' of undefined

转载 作者:行者123 更新时间:2023-11-30 12:14:01 28 4
gpt4 key购买 nike

我有以下简单的代码,但即使注入(inject)了 $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');
});
}
}

未捕获的类型错误:无法读取未定义的属性“get”我错过了什么?

最佳答案

您的 Controller 中已经有 $scope$http,因此您不需要将它们作为参数传递给函数 refresh。变化

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

$scope.refresh = function() {

一切正常

关于javascript - 即使在注入(inject) http 之后,Uncaught TypeError : Cannot read property 'get' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32921151/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com