Angular 6 Share module not work

不问归期 提交于 2019-12-11 17:43: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



来源:https://stackoverflow.com/questions/50270582/angular-6-share-module-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!