[英]TypeError: Service.functionName is not a function
我有这样的服务
angular.module('services').factory('DownloadService',[$resource,
function($resource){
return $resource('path/to/service/download', {}, {
downloadFile: {
method: 'GET',
url: 'path/to/service/download?fileID=:fileID'
}
});
}
]);
然后在控制器中,我有一个函数,我在其中调用此服务并在单击文件时调用该函数
angular.module('search').controller('MainCtrl', ['$scope','DownloadService',
function ($scope,DownloadService){
$scope.downloadDocument = function(id){
DownloadService.downloadFile({
fileId: id
});
};
}])
我收到此错误
TypeError:DownloadService.downloadFile is not a function...
你有错字
做nw loadFile
和
DownloadService.download FI乐
确保在创建search
模块时已将services
模块指定为依赖项,例如
angular.module('search', ['services', ...])
此外,请确保您在search
或它依赖的其他任何模块中都没有其他服务(名称为DownloadService
。
您可能只想在服务的DownloadService中添加alert
或console.log
,以确保已实例化该alert
或console.log
。
或更好的办法是,在两个地方都将其重命名为唯一的名称(例如myDownloadService
)。
console.log(new DownloadService())
并检查对象的$downloadFile
也是确保angular正在注入正确服务的另一种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.