Modal Controller Error in provider


Hello i have an error to open modal in a provider.
i attempted to open a modal in my provider with the next code:

let mapaModal = this.modalCtrl.create(HomePage);

I already insert de Provider in app.module.ts, but when i run the application give mi this error:

if i remove this line of code the application works.
But why?


What does your HomePage controller look like?


my home page calls to a function of my Provider. This function attempts to open a modal page, but throws these error.

this si the Provider code:

if i comment the line:
the application works but i cant open the modal.

Sorry for my bad english and thanks for help.


This is my home.ts:

this is the final part of the file

the error looks like i cant use a modalController in a provider to push a modal page .


The issue will be with HomePage itself based on the error message. Have you added HistorialProvider to your providers list?


Yes, i added the HistorialProvider to my providers list:

And the Provider works whithout these line that i said… I dont understand.


I suspect you have a circular dependency. I consider it broken design to access view layer things (like modals) from providers, but I realize that this may not be a particularly mainstream opinion. It does, however, protect one from such problems.


Thanks but, it is a course and i follow instructions. I change my code to access Modal from component, no from provider.


Hello, I do not know if it help you. I had the same error, I checked it and found this line:
import {ModalController} from “ionic-Angular”;
change for:
import {ModalController} from “ionic-angular”;

It’s solved.