[FIXED] App.Module imports not working on Ionic pages

Issue

I am creating a directive that I want to use on my pages but whenever I import something to app.module it acts as if the pages are not children of app.module. If I import the directive directly to the page module it works and the text is highlighted. Is there a way to make my pages a child of app.module or do I need to create a separate module to store all of my pages?

app.module.ts

    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { RouteReuseStrategy } from '@angular/router';
    
    import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
    
    import { AppComponent } from './app.component';
    import { AppRoutingModule } from './app-routing.module';
    import {HttpClientModule} from '@angular/common/http';
    
    import { HighlightDirective } from './highlight.directive';
    
    
    @NgModule({
      declarations: [AppComponent, HighlightDirective,],
      imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, HttpClientModule],
      providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
      bootstrap: [AppComponent],
    })
    export class AppModule {}

parentpage.page.html

 <ion-header>
      <ion-toolbar>
        <ion-title>parentpage</ion-title>
        <ion-buttons slot="end">
          <ion-back-button defaultHref="home"></ion-back-button> 
       </ion-buttons>
      </ion-toolbar>
    </ion-header>
    
    <ion-content>
      <ion-text color="primary">
        <h2>Welcome</h2>
      </ion-text>
      <p appHighlight>Highlight me!</p>
    </ion-content>
    
    <ion-header collapse="fade" [translucent]="true">
      <ion-toolbar>
        <ion-title>Header</ion-title>
      </ion-toolbar>
    </ion-header>

Solution

I think that you’ll have to create another module and keep all your required imports/exports there and import that module in app.module.ts itself.

follow this: sharing modules

Answered By – Khushboo

Answer Checked By – Willingham (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published