簡體   English   中英

App.Module 導入在 Ionic 頁面上不起作用

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

我正在創建一個我想在我的頁面上使用的指令,但是每當我將某些內容導入 app.module 時,它就好像頁面不是 app.module 的子級一樣。 如果我將指令直接導入到頁面模塊,它會起作用並且文本會突出顯示。 有沒有辦法讓我的頁面成為 app.module 的子頁面,或者我是否需要創建一個單獨的模塊來存儲我的所有頁面?

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>

我認為您必須創建另一個模塊並將所有必需的導入/導出保留在那里,並將該模塊導入 app.module.ts 本身。

按照這個:共享模塊

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM