I am trying to call component method from service class, but I am getting an error like 'ERROR TypeError: Cannot read property 'test' of undefined'. But I went through similar kind of issues but there mostly explaining about component to component calling, so I am not understanding properly.
Example: Testcomponent.ts
@Component({
selector:'component'
})
export class Testcomponent{
test(){
console.log('test method');
}
}
@Injectable()
export class Testservice {
private testcomp: Testcomponent;
// service method
dummy(){
//trying to call component method
testcomp.test();
}
}
This is the how I am calling, I am not sure this is correct approach or not, So can any one plz me to understand how to call component method from service.
I went through this ref in stack but not getting what exactly doing How to call component method from service? (angular2)