I am building an Angular service for some re-usable code for an upload named 'UploadService' which gets called within a controller below - even though the service has been loaded in I always get the following error
`UploadService.upload is not a function at h.$scope.uploadImage...)`
My Upload Service (UploadService.js)
abcdServices.service('UploadService', function(ApiService, $http, $localStorage, $location, $timeout, $q, $rootScope, Upload) {
var UploadService = function() {
this.upload_in_progress = false;
this.attached_media = {
photos: [],
videos: []
}
};
UploadService.prototype.upload = function(files) {
console.log('get here');
};
return UploadService;
});
// My Controller where the service is called - note I have added this to the
$scope.uploadImage = function(files, fileIndex, imageIndex) {
console.log('existing upload image');
console.log(files); // this shows an array in the console log as expected
UploadService.prototype.upload(files);
}
// The controller has the service loaded in at the top and I have included UserService.js file in the index.php
abcdControllers.controller('PostController', function( $http, $rootScope, UploadService) {
UploadService.upload()directly not through the prototypeUploadService.prototype.upload()becauseUploadServiceis not a reference to the class, angularjs' injector gives you an instance of that class.