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


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?


    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';
      declarations: [AppComponent, HighlightDirective,],
      imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, HttpClientModule],
      providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
      bootstrap: [AppComponent],
    export class AppModule {}


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


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