Skip to content

feat: Each Ionic component has its own module in Angular #27280

Description

@PatrikHorvatic

Prerequisites

Describe the Feature Request

Angular v15 has enabled importing only parts of CommonModule. I suggest Ionic exports all components in separate modules.

Describe the Use Case

It's really common you do not need all directives and pipes CommonModule offers, but only ngFor and ngIf directives in your page. Since Angular v15 you don't need to import CommonModule, you can import NgFor and NgIf in your page module.

Let's say you only need 'ion-content' and 'ion-searchbar' components in your page. You would need to import IonicModule in your page module. I suggest enabling importing only IonContentModule and IonSearchbarModule, since you only need these two components.

Describe Preferred Solution

With use cases described above, I suggest exporting each component in it's own module, for example, 'ion-content' component in IonContentModule, ''ion-searchbar' in IonSearchbarModule etc.

Describe Alternatives

No response

Related Code

Let's take really simple RegisterOptionsPage

HTML

<ion-content>
  <div class="pageContainer">
        <app-option-select-card [title]="LANGUAGE[3] | language" [subtitle]="LANGUAGE[4] | language"
          (cardClicked)="goTo('user')" ikona="userIconInactive" />
        <app-option-select-card [title]="LANGUAGE[5] | language" [subtitle]="LANGUAGE[6] | language"
          ikona="businessIconInactive" (cardClicked)="goTo('company')" />
  </div>
</ion-content>

MODULE
Here is RegisterOptionsPageModule

import { NgModule } from '@angular/core';
import { IonicModule } from '@ionic/angular';
import { RegisterOptionsPage } from './register-options.page';
import { VariousComponentsModule } from 'src/app/Components/Various/VariousComponents.module';
import { LanguagePipeModule } from 'src/app/Pipes/Language/LanguagePipe.module';

@NgModule({
  imports: [
    IonicModule,
    VariousComponentsModule, LanguagePipeModule
  ],
  declarations: [RegisterOptionsPage],
  exports: [RegisterOptionsPage]
})
export class RegisterOptionsPageModule { }

With this feature implemented, RegisterOptionsPageModule would look like this:

import { NgModule } from '@angular/core';
import { IonContentModule } from '@ionic/angular';
import { RegisterOptionsPage } from './register-options.page';
import { VariousComponentsModule } from 'src/app/Components/Various/VariousComponents.module';
import { LanguagePipeModule } from 'src/app/Pipes/Language/LanguagePipe.module';

@NgModule({
  imports: [
    IonContentModule,
    VariousComponentsModule, LanguagePipeModule
  ],
  declarations: [RegisterOptionsPage],
  exports: [RegisterOptionsPage]
})
export class RegisterOptionsPageModule { }

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions