web-dev-qa-db-ja.com

Angular 6:機能モジュール間でのコンポーネントの共有が機能しない

2つの機能モジュール(PagesSharedModuleHomeModule)を作成しました。
PagesSharedModuleのコンポーネントのテンプレート内でHomeModuleからエクスポートされたコンポーネントを使用しようとすると、次のエラーが発生します。

ERROR Error: Uncaught (in promise): Error: Template parse errors: 'app-main-menu' is not a known element:
1. If 'app-main-menu' is an Angular component, then verify that it is part of this module.
2. If 'app-main-menu' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR
->]<app-main-menu></app-main-menu>"): ng:///HomeModule/HomeComponent.html@0:0 Error: Template parse errors: 'app-main-menu' is not a known element:
1. If 'app-main-menu' is an Angular component, then verify that it is part of this module.
2. If 'app-main-menu' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR
->]<app-main-menu></app-main-menu>"): ng:///HomeModule/HomeComponent.html@0:0
    at syntaxError (compiler.js:215)
    at TemplateParser.Push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14687)
    at JitCompiler.Push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:22687)
    at JitCompiler.Push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:22674)
    at compiler.js:22617
    at Set.forEach (<anonymous>)
    at JitCompiler.Push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:22617)
    at compiler.js:22527
    at Object.then (compiler.js:206)
    at JitCompiler.Push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:22526)
    at syntaxError (compiler.js:215)
    at TemplateParser.Push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14687)
    at JitCompiler.Push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:22687)
    at JitCompiler.Push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:22674)
    at compiler.js:22617
    at Set.forEach (<anonymous>)
    at JitCompiler.Push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:22617)
    at compiler.js:22527
    at Object.then (compiler.js:206)
    at JitCompiler.Push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:22526)
    at resolvePromise (zone.js:814)
    at resolvePromise (zone.js:771)
    at zone.js:873
    at ZoneDelegate.Push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:3751)
    at ZoneDelegate.Push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
    at Zone.Push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)

違いが生じる場合、HomeModuleはルーティングされた遅延ロードモジュールです。

私のコード:

src/app/pages/pages-shared/pages-shared.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MainMenuComponent } from './main-menu/main-menu.component';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [
    MainMenuComponent
  ],
  exports: [
    MainMenuComponent
  ]
})

export class PagesSharedModule { }

src/app/pages/pages-shared/main-menu/main-menu.component.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-main-menu',
  templateUrl: './main-menu.component.html',
  styleUrls: ['./main-menu.component.scss']
})
export class MainMenuComponent implements OnInit {
  constructor() { }
  ngOnInit() { }
}

src/app/pages/home/home.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HomeComponent } from './home.component';
import { HomeRoutingModule } from './home-routing.module';
import { PagesSharedModule } from 'src/app/pages/pages-shared/pages-shared.module';

@NgModule({
  imports: [
    CommonModule,
    HomeRoutingModule,
    PagesSharedModule
  ],
  declarations: [
    HomeComponent
  ]
})

export class HomeModule { }

src/app/pages/home/home.component.html

<app-main-menu></app-main-menu>

src/app/pages/pages-routing.module.ts

...
{
  path: '',
  component: PagesComponent,
  children: [
    {
      path: '',
      pathMatch: 'full',
      loadChildren: './home/home.module#HomeModule'
    },
    {
      path: 'about',
      pathMatch: 'full',
      loadChildren: './content/content.module#ContentModule'
    },
    { path: '**', component: PageNotFoundComponent }
  ]
},
...

src/app/pages/home/home-routing.module.ts

{
  path: '',
  pathMatch: 'full',
  component: HomeComponent
}


何が間違っているのですか?
ありがとう。

5
Pini

更新:
信じられない!!!
angular CLIを停止して再度提供しましたが、コードを変更することなくすべて完全に機能しています。
他の誰かが同じ問題に直面している場合に備えて、このメモをここに残します...

4
Pini