简体   繁体   English

找不到“{模块名称}”的 NgModule 元数据中的错误

[英]ERROR in No NgModule metadata found for '{Module Name}'

I am using the following Version of CLI:我正在使用以下版本的 CLI:

ngular CLI: 6.2.7
Node: 10.6.0
OS: darwin x64
Angular: 6.1.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.8.7
@angular-devkit/build-angular     0.8.7
@angular-devkit/build-optimizer   0.8.7
@angular-devkit/build-webpack     0.8.7
@angular-devkit/core              0.8.7
@angular-devkit/schematics        0.8.7
@angular/cli                      6.2.7
@ngtools/webpack                  6.2.7
@schematics/angular               0.8.7
@schematics/update                0.8.7
rxjs                              6.2.2
typescript                        2.9.2
webpack                           4.16.4

I created a child ng Module with name char-routing.module.ts and when i tried to crate class its throwing error When i run the ng serve it Throw following Error:我创建了一个名为char-routing.module.ts的子 ng 模块,当我尝试创建类时抛出错误 当我运行 ng serve 时抛出以下错误:

ERROR in No NgModule metadata found for 'CharRoutingModule'.

I am using lazyloading of NgModule loadChildren: './add-character/add-character.component#CharRoutingModule' I am adding my source of my two file.我正在使用 NgModule loadChildren: './add-character/add-character.component#CharRoutingModule'延迟loadChildren: './add-character/add-character.component#CharRoutingModule' add- loadChildren: './add-character/add-character.component#CharRoutingModule' character.component loadChildren: './add-character/add-character.component#CharRoutingModule'我正在添加我的两个文件的源。 I am not able to replicate the issue why this happen, I am new in angular so, I don't have much more idea about it.我无法复制为什么会发生这种情况的问题,我是 angular 新手,所以我对此没有更多的想法。 Code of char-routing.module.ts char-routing.module.ts代码

import { NgModule } from '@angular/core';
import { AddCharacterComponent } from './add-character.component';
import { RouterModule } from '@angular/router';

@NgModule({
  imports: [RouterModule.forChild([
    {path: '', component: AddCharacterComponent}
  ])],
  declarations: [AddCharacterComponent]
})
    export class CharRoutingModule {

}

Code of add-character.component.ts add-character.component.ts代码

import { StarWarService } from './../star-war.service';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-add-character',
  templateUrl: './add-character.component.html',
  styleUrls: ['./add-character.component.css']
})
export class AddCharacterComponent implements OnInit {
  ablavelSide: {display: string, value: string}[] = [
    {display: 'None', value: ''},
    {display: 'Light', value: 'light'},
    {display: 'Dark', value: 'dark'}
  ];
  swService: StarWarService;
  constructor(serive: StarWarService) {
    this.swService = serive;
  }

  ngOnInit() {
  }

  onSubmit (form) {
    console.log(form);
    if (form.invalid) {
      return;
    }
    this.swService.addCharracter(form.value.name, form.value.side);
    form.reset();
  }
}

This is the code which i am using.这是我正在使用的代码。 Please help me.请帮我。

You're supplying the wrong path to your CharRoutingModule file.您为CharRoutingModule文件提供了错误的路径。

loadChildren: './add-character/add-character.component#CharRoutingModule'

should have been本来应该

loadChildren: './add-character/char-routing.module#CharRoutingModule'

Ideally though, there should be a CharModule that should be referenced in the loadChildren and then a CharRoutingModule that would contain the route config for CharModule理想的情况是,虽然,应该有应该在被引用的CharModule loadChildren然后CharRoutingModule将包含路由配置CharModule

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM