本文介绍了Angular 6 Share 模块不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 Angular 6 应用程序,我需要任何页面或某些页面的共享标题,我包含这个但不工作.我怎么了?获取演示 https://angualr-6-shared-module-work.stackblitz.io 路由登录 url 时显示错误 ** 并在此处出错 ** "

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>

这是我的代码:在应用模块中

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 { }

登录模块是

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 { }

路由器模块是

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 {}

推荐答案

需要在HeaderModule中导出HeaderComponent

You need to export HeaderComponent in HeaderModule

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

WORKING STACKBLITZ

这篇关于Angular 6 Share 模块不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 02:47