title: how to access lazy loaded service methods from caller method?
body: <p>In my module I am lazy loading(<code>lazy.module.ts</code>) a module from <code>app.component.ts</code> by using a testService. After successfully loaded the function I need to access a function from where I loaded the module. How can I achieve?</p>
  
  <p><strong>app.component.ts</strong></p>
  
  <pre><code>import { Component } from '@angular/core';
  import { TestService } from './test.service';
  
  @Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
  })
  export class AppComponent implements OnInit {
  
    constructor(private _testService: TestService) {}
  
    //lazy start
    public loadme = function(){
  
      console.log('begin load')
      this._testService.load();    
    }
  }
  </code></pre>
  
  <p><strong>app.component.html</strong></p>
  
  <pre><code>&lt;button (click)="loadme()"&gt;Load me&lt;/button&gt;
  </code></pre>
  
  <p><strong>test.service.ts</strong></p>
  
  <pre><code>import { Injectable, NgModuleFactoryLoader, Injector, NgModuleRef } from '@angular/core';
  
  @Injectable({ providedIn: 'root', })
  export class TestService {
  
    constructor(
      private loader: NgModuleFactoryLoader,
      private injector: Injector
    ) { }
  
    private moduleRef: NgModuleRef&lt;any&gt;;
  
    load(): void {
  
          const path = 'src/app/lazy.module#LazyModule'
          this
              .loader
              .load(path)
              .then(moduleFactory =&gt; {
                  this.moduleRef = moduleFactory.create(this.injector).instance;                
                 console.log('loaded');  
  
                 //I NEED TO ACCESS THE 
                 //lazyService.hello()   function here
              })
              .catch(err =&gt; {
                  console.error('error loading module', err); 
              });
  
    }
  }
  </code></pre>
  
  <p><strong>lazy.module.ts</strong></p>
  
  <pre><code>import { NgModule } from '@angular/core';
  import { CommonModule } from '@angular/common';
  import { LazyService } from './lazy.service';
  
  @NgModule({
    declarations: [],
    imports: [ CommonModule ],
    providers:[ LazyService ]
  })
  export class LazyModule { }
  </code></pre>
  
  <p><strong>lazy.service.ts</strong></p>
  
  <pre><code>import { Injectable } from '@angular/core';
  
  @Injectable()
  export class LazyService {
  
    constructor() {    
      console.log('lazy service constructed');    
    }
  
    //I NEED TO ACCESS THIS FUNCTION RIGHT AFTER LAZY LOADS
    public hello = function():void{
  
      console.log('Hello from lazy service');
    }
  }
  </code></pre>