I'm currently working on integrating TypeScript into an existing Angular 1.5 application. Despite successfully using Angular services and third-party services, I am facing difficulties in injecting custom services that are written in vanilla JavaScript. Specifically, I need to inject the reportService as shown in the example below.
The issue I encounter is receiving an error stating 'getReportById' is not a function.
class ReportController implements IReportController {
static $inject = ['$stateParams', 'reportService'];
constructor(private $stateParams: angular.ui.IStateParamsService, private reportService) {
this.getReport($stateParams.id);
}
getReport(id: number): object {
reportService.getReportById(id)
.then(function(res) {
console.log(res)
});
}
}
Below is the service code:
angular.module('reportsServiceModule', [])
.factory('reportsService', [
'$http',
reportsService
]);
function reportsService(
$http
) {
'use strict';
var service = {};
service.getReportById = function(reportID) {
return 'A promise';
};
return service;
}