title: How to call a component method from service class - Angular
body: <p>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.</p>
  
  <p>Example:
  Testcomponent.ts</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>@Component({
    selector:'component'
  })
  export class Testcomponent{
  
    test(){ 
      console.log('test method');
    }
  }</code></pre>
  </div>
  </div>
  
  Testservice.ts</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>@Injectable()
  
  export class Testservice {
  
  private testcomp: Testcomponent;
  
  // service method
  dummy(){
    //trying to call component method
    testcomp.test();
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>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.</p>
  
  <p>I went through this ref in stack but not getting what exactly doing <a href="https://stackoverflow.com/questions/40788458/how-to-call-component-method-from-service-angular2">How to call component method from service? (angular2)</a></p>