角入口组件

时间:2019-03-17 12:41:28

标签: angular angular-module

我想打开ManagePointsDialogComponent作为对话框。当我单击addPoints函数时,出现错误。

我的懒惰模块: users.management.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { SharedModule } from "../../shared/shared.module";
import { UsersListComponent } from './screens/users-list/users-list.component';
import { UsersManagementRoutingModule } from './users-management-routing.module';
import { UsersManagementComponent } from './components/users-management/users-management.component';
import { UserCreateComponent } from './screens/user-create/user-create.component';
import { UserDetailsComponent } from './screens/user-details/user-details.component';
import { ManagePointsDialogComponent } from './components/manage-points-dialog/manage-points-dialog.component';

@NgModule({
  declarations: [
    UsersListComponent,
    UserCreateComponent,
    UserDetailsComponent,
    UsersManagementComponent,
    ManagePointsDialogComponent,
  ],
  imports: [
    CommonModule,
    SharedModule,
    UsersManagementRoutingModule,
  ],
  entryComponents: [
    ManagePointsDialogComponent,
  ]
})
export class UsersManagementModule { }

此组件在惰性模块内部。从这个组件,我想打开对话框。 users-list.component.ts

constructor(private dialog: MatDialog) { }

private addPoints(id: string): void {
   this.dialog.open(ManagePointsDialogComponent, ManagePointsDialogComponent.buildConfiguration({addPoints: true, actionText: 'Add'}))
}

怎么了?

UsersListComponent.html:28 ERROR Error: No component factory found for ManagePointsDialogComponent. Did you add it to @NgModule.entryComponents?
    at noComponentFactoryError (core.js:9876)
    at CodegenComponentFactoryResolver.push../node_modules/@angular/core/fesm5/core.js.CodegenComponentFactoryResolver.resolveComponentFactory (core.js:9914)
    at CdkPortalOutlet.push../node_modules/@angular/cdk/esm5/portal.es5.js.CdkPortalOutlet.attachComponentPortal (portal.es5.js:654)
    at MatDialogContainer.push../node_modules/@angular/material/esm5/dialog.es5.js.MatDialogContainer.attachComponentPortal (dialog.es5.js:195)
    at MatDialog.push../node_modules/@angular/material/esm5/dialog.es5.js.MatDialog._attachDialogContent (dialog.es5.js:1046)
    at MatDialog.push../node_modules/@angular/material/esm5/dialog.es5.js.MatDialog.open (dialog.es5.js:850)
    at UsersListComponent.push../src/app/lazy-modules/users-management/screens/users-list/users-list.component.ts.UsersListComponent.addPoints (users-list.component.ts:48)
    at Object.action (users-list.component.ts:18)
    at Object.eval [as handleEvent] (UsersListComponent.html:33)
    at handleEvent (core.js:23106)

1 个答案:

答案 0 :(得分:0)

如果将其添加到应用程序模块中可能会起作用,因为有时entryComponents在延迟加载中无法很好地工作。希望对您有帮助