Ionic 4 - popover component and lazy load

  • usually i don’t need to declare other modules in app.module because those are lazy loaded by the router
  • however i’ve created a shared service provider that wrap popover.create to quickly create one
  • for some reason if i launch popoverController.create() from within this service it will not see my popover child component - it works of course if i run the code from within the page
  • i also tried passing a string instead of the object but its the same

Is there a way to force my popover component to be resolved before invoking the function in the service?

I might be wrong but I think that it was already the case per design in Ionic v3.

Page controller, modal and other popover have to be use in the pages or components respectively should not/can’t be use in service

Spontaneously I would say that these component needs to have access to the Dom and are presentation components, that’s why they can’t be used in services

But again, I might be wrong

I should try to use them in a service that does not run with “inroot” i.e. app.module.

Its a bit tedious to write the code for popover every time - i’ve found a way to creare a function that uses Angular @Inject but this approach only works for loader, toast and alert not for popoover

You don’t have to write the code many times, you’ve got different pattern to solve that.

One for example could be using a service with an observable. You subscribe to it in app.component where you create/display the popover and you trigger the service from the pages/components

Or another pattern would be to use an abstract component

You mean abstract providers like this?

No I mean like an abstract page or component like https://github.com/fluster/fluster-app/blob/7931a07635eb1f8f682c996f243a5ebf4906c4ae/src/app/pages/abstract-page.ts#L103

But I would suggest the first option with an observable and service, with the time I think that this would be a cleaner solution