Ionic - How can I inject Page to Provider


I have AddPage and Provider.

AddPage has a method and I want to call it on Provider.

So I imported { AddPage } from ‘…/…/pages/add/add’; and inject dependency(public add:AddPage on constructor)

import { AddPage } from '../../pages/add/add';
    public add: AddPage

but it gives me an error below and I can only see white screen when I run it on android emulator.

I know injecting a Page on Provider to use method is unusual(maybe improper), but I’d like to use that way anyway.

Is there any solution?

A page is not injectable (does not have the @Injectable decorator) and I don’t think it should ever be.

If you need a function from your page then maybe this function needs to be in a provider (either the provider you’re trying to inject the page into or another one).

What are you really trying to do (to really answer your question)?


Thanks, that is clear answer.

I just didn’t want to implement new Provider to use a method that will be called only one time.

Now I realized that just implementing a Provider is more simple than looking for how not to do that.

Thanks, again. :slight_smile: