OshoParth OshoParth - 5 months ago 38
TypeScript Question

Componet issue in ionic 3

I have created few pages in an ionic app but while invoking the page I get the following error

Uncaught (in promise): Error: No component factory found for BoxPage. Did you add it to @NgModule.entryComponents?
However i have added the page details to the
app.component.ts
as
import { BoxPage } from '../pages/box/box';
but still the issue persists. I have implemented some pages like home,product details and cart etc but any newly created pages show the error similar issue persists for few other newly created pages too.
Any suggestions about the solution to the issue.

Answer Source

Just like the error says:

Error: No component factory found for BoxPage. Did you add it to @NgModule.entryComponents?

You need to add that page (component) to the @NgModule of your app.module.ts file. You can find more info in Ionic docs:

No component factory found for...

This error happens when you are trying to use a component, provider pipe or directive that has not been imported and added to your ngModule. Whenever you add a new component, provider, pipe or directive to your app, you must add it to the ngModule in the src/app/app.module.ts file for Angular to be able to use it. To fix this error you can import the offending component, provider, pipe or directive into the app.module file and then if it is a provider add it to the providers array and for a component, pipe or directive add it to both the declarations array and entryComponents array.

So in this case, you'd need to add it to both, the entryComponents and declarations arrays:

import { BoxPage } from 'the/path/to/the/file';
// ...

@NgModule({
    declarations: [
        // ...
        BoxPage // <- Here!
    ],
    imports: [
        // ...
    ],
    bootstrap: [IonicApp],
    entryComponents: [
        // ...
        BoxPage // <- and also here!
    ],
    providers: [
        // ...
    ]
})
export class AppModule { }