Clarification on Ionic /components folder

ionic g component DeviceFieldComponent

Generates:

device-field.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { DeviceFieldComponent } from './device-field';

@NgModule({
  declarations: [
    DeviceFieldComponent,
  ],
  imports: [
    IonicPageModule.forChild(DeviceFieldComponent),
  ],
  exports: [
    DeviceFieldComponent
  ]
})
export class DeviceFieldComponentModule {}

Then, is this a bug, and it should be

  imports: [
    IonicModule,
  ],

?

No, it is not a bug. IonicModule and IonicPageModule are totally unrelated and not interchangeable. IonicPageModule sets up the entry in the module loader table that enables the navigation system to be able to navigate using strings. IonicModule must be imported in any submodule containing components that incorporate Ionic components in their templates. Similarly, CommonModule must be imported if you are using things like ngFor.

Then,

  1. If we want to create a component, (let’s imagine, just a custom canvas with some functions), we should use IonicModule?

  2. When should we use, in a component, IonicPageModule? (Just in pages, I suposse?)

Thanks,

Only if it incorporates any <ion-*> elements.

Never.

Right.

Ok.

Then, ionic team should change the generated code for the command:


ionic g component myComponent

Because it generates the wrong code with this Import (IonicPageModule.)

Because if you want to generate a page, you have

ionic g page MyPage

Isn’t it?

1 Like

I don’t use the generators; I don’t see net value in the concept.

I’ll raise a bug. Just for people that use them :).

Thanks for the explanations :slight_smile:

Pls how did you solve this Ionic 3/Component issue, am having the same problem after using ionic g component componentname. I have read through this tread, pls i need a straight forward response from you. plsss