Angular开发问题:Uncaught Error: Component UserComponent is not part of any NgModule

Angular开发问题:Uncaught Error: Component UserComponent is not part of any NgModule

异常问题:

用angular开发项目时候比较常见错误,打开浏览器,页面刷新不出来,控制台报错:

Uncaught Error: Component UserComponent is not part of any NgModule or the module has not been imported into your module.
at JitCompiler.push…/node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._createCompiledHostTemplate (vendor.js:62394)
at vendor.js:62370
at Array.forEach ()
at vendor.js:62367
at Array.forEach ()
at JitCompiler.push…/node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (vendor.js:62356)
at vendor.js:62284
at Object.then (vendor.js:39005)
at JitCompiler.push…/node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (vendor.js:62283)
at JitCompiler.push…/node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler.compileModuleAsync (vendor.js:62243)

错误原因:

访问对应url时候,UserComponent 没有在NgModule 导入配置中,浏览器找不到组件造成。

解决办法:

将UserComponent加入到AppModulel类中,刷新页面即可。

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    PageNotFoundComponent,
    IndexComponent,
    MainComponent,
    LeftNavComponent,
    LeftMenuClickPopup,
    ManpowerInputComponent,
    ManpowerAddComponent,
    ManpowerUserlistComponent,
    UserDialogComponent,
    UserComponent,
    RoleComponent,
    RightComponent
  ],

你可能感兴趣的:(angular)