I'm trying to figure out how to use TypeScript in an existing Angular 1.5 app. I can't figure out how to inject custom services. Angular services and 3rd party services work fine. The services I need to inject are still vanilla JS services. In the example below I need to inject reportService.
The error I get is 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)
});
}
}
Here is the service.
angular.module('reportsServiceModule', [])
.factory('reportsService', [
'$http',
reportsService
]);
function reportsService(
$http
) {
'use strict';
var service = {};
service.getReportById = function(reportID) {
return 'A promise';
};
return service;
}
anytype, but you won't benefit from TS this way. Do you have particular problems with the code above?