我有以下简单的代码,但即使注入了$ 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'未定义的 我错过了什么?
答案 0 :(得分:3)
您的控制器中已经有$scope
和$http
,因此您无需将它们作为参数传递给函数refresh
。变化
$scope.refresh = function($scope, $http) {
到
$scope.refresh = function() {
它应该都可以正常工作