1

I have a secondary module of the AppModule, in this case, it is called DriverModule, and within that module, I have the DriversService service added within the providers array. Within the DriversModule, I have children routes that I charge using lazy modules.

The service works well within all pages under DirverModule.

My problem is when I try to put a modal into that service that is running on all the daughter pages of DriversModule, I get this error:

ERROR Error: Uncaught (in promise): Error: No component factory found for ServiceOfferingComponent. Did you add it to @NgModule.entryComponents?
Error: No component factory found for ServiceOfferingComponent. Did you add it to @NgModule.entryComponents?
    at noComponentFactoryError 

Even though I already put the component inside the declarations and entryComponents arrays.

import { ServiceOfferingComponent } from './service-offering/service-offering.component';

@NgModule({
  declarations: [
    ServiceOfferingComponent
  ],
  imports: [
    RouterModule.forChild(routes)
  ],
  providers: [
    DriverService,
  ],
  entryComponents: [
    ServiceOfferingComponent
  ]
})
export class DriverModule { }

import { ServiceOfferingComponent } from './service-offering/service-offering.component';


import { ModalController } from '@ionic/angular';

@Injectable()
export class DriverService {

constructor(
    public modalController: ModalController
  ) { 
    someObservable$.subscription((val:boolean) =>{
        if(val) this.showServiceOfferingModal();
    });
 }

async showServiceOfferingModal() {
    const modal = await this.modalController.create({
      component: ServiceOfferingComponent,
      backdropDismiss: false
    });
    await modal.present();
  }

}

My assumption is that if the service works well within all the daughter routes of DriversModule I can present the modal on the current daughter page, no matter on which daughter page of the DriversModule I am browsing as long as the service is available. But apparently, that assumption is incorrect.

Do you know any technique to put a modal into a service and when a condition arises, present the modal on the page that the user is browsing, regardless of which page it is as long as it is the daughter page of the DriversModule?

Radecom System
  • 192
  • 1
  • 1
  • 8
  • Can you remove the call to `showServiceOfferingModal()` in the constructor and call it from a components `ngOnInit`? I suspect that the reason you get this error is because the component is not ready when the `DriverService` is instantiated – Mendy Aug 14 '19 at 00:37
  • Also check if this answer is relevant in your case https://stackoverflow.com/a/51831884/5253155 – Mendy Aug 14 '19 at 00:37
  • I already tried, I even tried it on the `ionViewDidEnter()` and neither, I think it is impossible to achieve put a modal into a service. – Radecom System Aug 14 '19 at 16:10

0 Answers0