いくつかのページ内にカスタムコンポーネントを追加しようとしています。
ionic g pages name
ionic g component name
この時点で私はこれを試してみます:
<ion-content>
<app-menu-button></app-menu-button>
</ion-content>
app-menu-buttonはコンポーネントセレクターです
このエラーが発生します: 1. If 'app-menu-button' is an Angular component, then verify that it is part of this module.
app-moduleファイルにこれを追加しようとしています:
exports: [
MenuButtonComponent
]
しかし、それは機能しません。
私の目標は、このコンポーネントを複数のページに表示することです。
ありがとう、
遅延読み込みを使用している場合は、カスタムコンポーネントをページモジュールにインポートする必要があります。例:AppMenuButtonComponent
と呼ばれるページでコンポーネントを使用するExamplePage
場合は、ページモジュールにインポートする必要があります。
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { ExamplePage } from './example';
import { AppMenuButtonComponent } from '../../components/appmenubutton/appmenubutton';
@NgModule({
declarations: [
ExamplePage,
AppMenuButtonComponent
],
imports: [
IonicPageModule.forChild(ExamplePage),
],
exports: [
ExamplePage,
]
})
export class ExamplePageModule {
}
カスタムコンポーネントの作成時に自動的に追加されたapp.module.tsファイルからインポートと宣言を削除することを忘れないでください。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加