У меня есть модуль, который выглядит примерно так:
@NgModule({
imports: [
EmployeeRoutingModule,
],
declarations: [
ListEmployeeComponent,
EmployeeDialogComponent,
],
providers: [
EmployeeService,
BsModalService,
],
entryComponents: [
EmployeeDialogComponent,
]
})
export class EmployeeModule {
}
И он импортируется в модуль приложения примерно так:
{
path: 'employee',
loadChildren: './employee/employee.module#EmployeeModule'
},
внутри app.routing.ts
.
Когда я пытаюсь использовать EmployeeDialogComponent
в моем EmployeeModule
, он продолжает выдавать ошибку
ERROR Error: No component factory found for EmployeeDialogComponent. Did you add it to @NgModule.entryComponents?
Если я добавлю его в модуль (назовем его SharedModule
) так же, какзагружается во время выполнения приложения (в файле app.module.ts
) это работает.Кажется, что-то об использовании его лениво.
В чем проблема и как я могу ее решить?
Вот пример минимальной версии модального режима, которая не будет работать:
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {BsModalRef} from 'ngx-bootstrap';
@Component({
selector: 'modal-content',
template: `
<div class="modal-body text-center">
<p class="lead mb-5">{{ message }}</p>
<button type="button" class="btn btn-lg btn-outline-secondary mr-5" (click)="decline()" >{{ btnNoText }}</button>
<button type="button" class="btn btn-lg btn-success" (click)="confirm()" >{{ btnYesText }}</button>
</div>
`
})
export class ConfirmEmployeeModalComponent implements OnInit {
@Output() result = new EventEmitter<boolean>();
message = 'Are you sure?';
btnNoText = 'No';
btnYesText = 'Yes';
constructor(public bsModalRef: BsModalRef) {
}
ngOnInit() {}
confirm(): void {
this.result.emit(true);
this.bsModalRef.hide();
}
decline(): void {
this.result.emit(false);
this.bsModalRef.hide();
}
}
В модуле ListEmployeeComponent
есть компонент, который содержит такую функцию:
import {
Component,
NgZone,
ElementRef,
OnInit,
ViewContainerRef,
PipeTransform,
Pipe,
ViewChild
} from '@angular/core';
import {FormControl} from '@angular/forms';
import {DialogService, BuiltInOptions} from "ngx-bootstrap-modal";
//import { EmployeeDialogComponent } from '../employee-dialog/employee-dialog.component';
import {EmployeeService} from "../employee.service";
import {LocalStorageUtilityService, NotificationService} from "../../common/common.services";
import * as _ from 'lodash';
//import { NotifyDialogComponent } from '../../common/dialog/notify-dialog/notify-dialog.component';
import {UserService} from "../../common/user.service";
import {ConfirmModalComponent} from "../../common/confirm-modal/confirm-modal.component";
import {BsModalService} from "ngx-bootstrap/modal";
import {EmployeeDialogComponent} from "../employee-dialog/employee-dialog.component";
import {ConfirmEmployeeModalComponent} from "../confirm-employee-modal/confirm-modal.component";
@Component({
templateUrl: 'list-employee.component.html',
styleUrls: ['./list-employee.component.css']
})
export class ListEmployeeComponent {
constructor(
private modalService: BsModalService,
public _dialogService: DialogService,
public _companyService: EmployeeService,
public _notificationService: NotificationService,
private userService: UserService,
) {
}
showAddEmployeeDialog = () => {
this.modalService.show(ConfirmEmployeeModalComponent, {}).content.result.subscribe((details: any) => {
}
);
}
}