Angular 6 Share module not work

2019-08-29 15:16发布

问题:

I am Create an angular 6 application, i have need a share header for any page or some pages, i include this but not working. What's I am wrong ?. get DEMO https://angualr-6-shared-module-work.stackblitz.io error show when I am routing the login url ** and error here** "

Error: Uncaught (in promise): Error: Template parse errors:
'app-primery-header' is not a known element:
1. If 'app-primery-header' is an Angular component, then verify that it is part of this module.
2. If 'app-primery-header' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<app-primery-header></app-primery-header>

here my code: in App Module

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';

// routing 
import { AppRoutingModule } from './app-routing.module';

@NgModule({
  imports:      [ BrowserModule, FormsModule, AppRoutingModule ],
  declarations: [ AppComponent, HelloComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

Login Module Is

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LoginComponent } from './login.component';
import { LoginRoutingModule } from './login-routing.module';
import { PrimeryHeaderModule } from '../share';
@NgModule({
  imports: [
    CommonModule, LoginRoutingModule,PrimeryHeaderModule
  ],
  declarations: [LoginComponent]
})
export class LoginModule { }

Router module is

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
    { path: 'login', loadChildren: './login/login.module#LoginModule'}
];

@NgModule({
    imports: [RouterModule.forRoot(routes)],
    exports: [RouterModule]
})
export class AppRoutingModule {}

回答1:

You need to export HeaderComponent in HeaderModule

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

WORKING STACKBLITZ