I've created some simple class by this example https://www.typescriptlang.org/docs/handbook/classes.html with private and public methods, but I've got an error: ERROR TypeError: Cannot read property 'somePrivateMethod' of undefined
.
import { Injectable } from '@angular/core';
@Injectable()
export class MyService {
constructor() {}
somePublicMethod() {
this.somePrivateMethod();
}
private somePrivateMethod() {
return true;
}
}
I just call myService.somePublicMethod
from my component and do not use somePrivateMethod
.
I call it in my component like these:
constructor(
private myService: MyService
) { }
ngOnInit() {
inputs.map(this.myService.somePublicMethod)
}
I tired to solve it like this:
constructor(
private myService: MyService
) { }
ngOnInit() {
const myMethod = this.myService.somePublicMethod.bind(this)
inputs.map(myMethod)
}
But anyway I've got the same error. Where is the problem?