[英]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.我正在创建一个我想在我的页面上使用的指令,但是每当我将某些内容导入 app.module 时,它就好像页面不是 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 的子页面,或者我是否需要创建一个单独的模块来存储我的所有页面?
app.module.ts 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 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>
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.我认为您必须创建另一个模块并将所有必需的导入/导出保留在那里,并将该模块导入 app.module.ts 本身。
follow this: sharing modules按照这个:共享模块
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.