Two services are involved in this scenario, with the first service being injected into the second service like so:
rule.service.ts
@Injectable()
export class RuleService {
constructor(
private _resourceService: ResourceService
){}
someMethod(url: string) {
this._resourceService.getData(url).then((res) => {
console.log(res);
}
}
}
resource.service.ts
@Injectable()
export class ResourceService {
constructor(
http: Http
) { }
public getData(url?: string): Promise<T> {
//some code
}
}
service being called jQuery :(
private run(input: any, a_parameters: any) {
$("select[name='" + a_parameters[0] + "']").change(function(e: any) {
return new Promise((resolve) => {
let array: any[] = [];
this._resourceService.getData(a_parameters[1]).then(() => {
let result: any;
...
However, when attempting to call someMethod from RuleService, a console error occurs:
EXCEPTION: Uncaught (in promise): TypeError: Cannot read property 'getData' of undefined TypeError: Cannot read property 'getData' of undefined //error details..
If anyone can provide guidance on what might be wrong and how to properly implement services within services, I'd greatly appreciate it.