In the midst of my TypeScript angular project, I am aiming to revamp it by incorporating services. However, I have encountered an issue where when calling a function within the service, the runtime does not recognize it as the service class but rather the controller class. How can I successfully call functions within my service from the same service?
Below are snippets of the relevant code:
Helper Service
export interface IHelperService {
Log(msg: string): void;
GetModel(model: string): Array<any>;
}
export class HelperService implements IHelperService {
public GetModel(model: string): Array<any> {
return this.getModelEnum(model);
}
private getModelEnum(model: string): Array<any> {
...
}
}
let module: angular.IModule = angular.module("myApp", ["ngTouch"]);
module.service('HelperSvc', HelperService);
Controller
constructor($scope: angular.IScope, $http: angular.IHttpService, helperSvc: IHelperService) {
this.Scope.GetModel = helperSvc.GetModel;
}
HTML
<select ng-model="ae.Scope.Model"
ng-options="type.Id as type.Value for type in GetModel('Types')"></select>
Results in
Error: this.getModelEnum is not a function
Prior to this, everything worked smoothly when the GetModel and getModelEnum functions resided within the controller.
(I found it frustrating that search engines kept filtering out 'this' from my queries, resulting in irrelevant search outcomes...)