ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

How to load/use ionic directives, if component is declared in a module

Open aavelyn opened this issue 10 years ago • 9 comments

Short description of the problem:

I'm using rc0 tabs starter project and I want to have a auth folder with login and signup page inside the src folder (same level as pages).

here's the auth module

@NgModule({
    imports:[
        FormsModule,
        HttpModule
    ]
    declarations:[
                LoginPage
    ]
})

I import the the module in app.module.ts under imports and get

Unhandled Promise rejection: Template parse errors: 'ion-title' is not a known element...

Do I need to import the directives from ionic inside auth module?

What behavior are you expecting?

expecting ionic directive to work globally.

Which Ionic Version? ionic 2 rc.0

aavelyn avatar Sep 29 '16 15:09 aavelyn

try to add your LoginPage into entryComponents

so your example should look like this:

@NgModule({
    imports:[
        FormsModule,
        HttpModule
    ]
    declarations:[
                LoginPage
    ],
    entryComponents: [
                LoginPage
    ]
})

ekhmoi avatar Sep 29 '16 17:09 ekhmoi

Hello, thanks for opening an issue with us! Would you mind posting a repo I can use to reproduce this issue?

jgw96 avatar Sep 29 '16 17:09 jgw96

@jgw96 here's the repo Github

@ekhmoi adding LoginPage to entryComponents doesn't work either. entryComponents isn't a 'native' property of ngModule from angular isn't it?

aavelyn avatar Sep 30 '16 09:09 aavelyn

Hello, I have the same problem. Are feature componets supported ?

bkapo avatar Sep 30 '16 10:09 bkapo

Hey I figured out how to import feature modules correctly to avoid that error. Here's the forum post.

Hope that helps, Dharsan

SudharsanSukumar avatar Oct 02 '16 02:10 SudharsanSukumar

Hi Dharsan, Thanks!!!

it solves the issue and I agree with the posts over there, that it should be added to the docs immediately. Otherwise, people might start declaring everything inside app.module ignoring ngModules and the many benefits it's gonna bring (hopefully soon also to ionic 2)

For all other readers, you need to use IonicModule.forRoot() method to 'provide' ionic directives to your components:

@NgModule({ imports:[ IonicModule.forRoot(ComponentNeedingIonicDirectives) ], declarations: [ ComponentNeedingIonicDirectives ] })

aavelyn avatar Oct 10 '16 15:10 aavelyn

Juste add IonicModule to the imports. No need to call forRoot for the directive.

mcherb avatar Sep 03 '17 14:09 mcherb

@mcherb You saved my day after 5 hours of struggling. In the end it's quiet obvious though ..

JoeriShoeby avatar Nov 27 '17 15:11 JoeriShoeby

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Sep 01 '18 16:09 ionitron-bot[bot]