Angular 4 : 컴포넌트 팩토리를 찾을 수 없습니다. @ NgModule.entryComponents에 추가하셨습니까?


300

webpack과 함께 Angular 4 템플릿을 사용하고 있으며 구성 요소 (ConfirmComponent)를 사용하려고 할 때이 오류가 발생합니다.

ConfirmComponent에 대한 구성 요소 팩토리를 찾을 수 없습니다. @ NgModule.entryComponents에 추가 했습니까?

구성 요소는 app.module.server.ts

@NgModule({
  bootstrap: [ AppComponent ],
  imports: [
    // ...
  ],
  entryComponents: [
    ConfirmComponent,
  ],
})
export class AppModule { }

나는 또한이 app.module.browser.ts과app.module.shared.ts

어떻게 고칠 수 있습니까?


1
ConfirmComponent세부 정보를 어떻게 사용 하여 귀하의 질문에 대답하기에 충분하지
— 않습니까

안녕하세요. 구성 요소 가져 오기 {ConfirmComponent} from "../confirm.component/confirm.component";
— mrapi

2
입력 구성 요소에 대한 내용 은 다음을
— Max Koretskyi

공통 구성 요소로 작동하려는 경우 CommonModule의 선언 및 entryComponents에 넣고 다른 위치에서 제거 할 수 있습니다.
— Charitha Goonewardena

1
각도 대화 상자의 경우 동일한 오류 및 수정! freakyjolly.com/…
— Code Spy

답변:


437

에 이것을 추가하십시오 module.ts.

declarations: [
  AppComponent,
  ConfirmComponent
]

ConfirmComponent가 다른 모듈에있는 경우 해당 모듈을 내 보내서 외부에서 사용할 수 있도록 추가해야합니다.

exports: [ ConfirmComponent ]

--- 아이비가 명시 적으로 활성화 된 Angular 9 또는 Angular 8 업데이트

아이비가 포함 된 입력 구성 요소는 더 이상 필요하지 않으며 더 이상 사용되지 않습니다.

--- 아이비가 비활성화 된 Angular 9 및 8의 경우 ---

동적으로로드 된 컴포넌트의 경우 ComponentFactory를 생성하려면 컴포넌트를 모듈의 entryComponents에 추가해야합니다.

declarations: [
  AppComponent,
  ConfirmComponent
],
entryComponents: [ConfirmComponent],

entryComponents 정의에 따라

이 모듈을 정의 할 때 컴파일해야하는 구성 요소 목록을 지정합니다. 여기에 나열된 각 구성 요소에 대해 Angular는 ComponentFactory를 만들어 ComponentFactoryResolver에 저장합니다.


2
Hi.it은 이미 app.module.shared.ts에 있고 entryComponents는 app.module.server.ts에 있습니다
— mrapi

3
ConfirmComponent가 다른 모듈에있는 경우, 외부에서 사용할 수 있도록 내 보내야합니다. 다음을 추가하십시오. exports : app.module.shared.ts에서 [ConfirmComponent]
— Fateh Mohamed

1
github.com/ankosoftware/ng2-bootstrap-modal/blob/master/의 ng2-bootstrap-modal 구성 요소입니다 .
— mrapi

9
모두 감사합니다. !!!!!!! .. 같은 선언문에 모든 선언과 entryComponents를 입력하면 app.module.shared.ts가 문제를 해결했습니다
— mrapi

9
내보내기가 작동하지 않습니다 ... entryComponents 옵션이 작동합니다!.
— 라자 라마 모한 타 발람

132

세부 사항을 참조하십시오 에 대해 entryComponent:

구성 요소를 동적으로로드하는 경우 declarations및 entryComponent다음 모두에 구성 요소를 넣어야합니다 .

@NgModule({
  imports: [...],
  exports: [...],
  entryComponents: [ConfirmComponent,..],
  declarations: [ConfirmComponent,...],
  providers: [...]
})

5
고마워요, 고마워요 !!! 다른 구성 요소 안에 데이터를 입력하는 대화 상자를 만들었습니다 (대화 상자에는 다른 구성 요소 안에 구성 요소 선언이 있고 레이아웃에 대해서는 dialog.html이 있습니다)
— Ramon Araujo

3
이것은 나를 위해 속임수를 썼으며 선택된 답변보다 더 나은 설명을 가지고 있습니다. 감사합니다!
— Arsen Simonean

2
분명히 나에게 가장 좋은 대답!
— tuxy42

이것이 나를위한 해결책이었습니다. 나는 즉시 구성 요소를 만들고 있었고 올바른 모듈에 모든 것을 가지고 있었지만 여전히 오류가 발생했습니다. 내가 만든 구성 요소를 추가하는 entryComponents것이 해결책이었습니다. 감사합니다!
— 노바 스톰

2
ModalComponent 를 호출하는 내 구성 요소 는 구성 요소의 손자입니다. 어느 쪽도 아니 추가하지 ModalComponent 로를 entryComponents도에 추가 exports날 위해 일했습니다. 그러나 나는 손자가 아닌 다른 구성 요소에서 ModalComponent 를 호출 할 수 있습니다
— canbax

54

TL; DR :와 NG6에서 서비스 providedIn: "root"구성 요소가 첨가되지 않은 경우 ComponentFactory를 찾을 수 entryComponents의 app.module .

서비스에서 컴포넌트를 동적으로 작성하는 것과 함께 각도 6을 사용하는 경우에도이 문제가 발생할 수 있습니다!

예를 들어 오버레이 만들기 :

@Injectable({
  providedIn: "root"
})
export class OverlayService {

  constructor(private _overlay: Overlay) {}

  openOverlay() {
    const overlayRef = this._createOverlay();
    const portal = new ComponentPortal(OverlayExampleComponent);

    overlayRef.attach(portal).instance;
  }
}

문제는

제공 : "루트"

이 서비스를 제공하는 정의 app.module definition .

따라서 서비스가 예를 들어 OverlayExampleComponent를 선언하고 entryComponents에 추가 한 "OverlayModule"에있는 경우 서비스는 OverlayExampleComponent의 ComponentFactory를 찾을 수 없습니다.


3
Angular에만 해당되는 문제 6. @NgModule @NgModule ({entryComponents : [yourComponentName]})의 entryComponents에 구성 요소를 추가하여 문제를 해결합니다.
— DeanB_Develop

6
이것은 모듈 providedIn에서 providers옵션을 제거 하고 대신 사용하여 해결할 수 있습니다 .
— Knelis

정보를 주셔서 감사합니다,하지만 @NgModule에 추가는 ({..., entryComponents는 [...]이})도 providedIn과 나를 위해 일한 : "루트"
— Mykola Mykolayovich Dolynskyi

1
이것은 github.com/angular/angular/issues/14324 와 관련이있는 것 같습니다 . Angular 9
— Paolo Sanchi

특히 게으른 모듈에서 특히 그렇습니다. 이 문제를 해결하기 위해 NgModule.providers : [MyLazyLoadedModuleService]를 지정하고 MyLazyLoadedModuleService.providedIn을 "root"에서 MyLazyLoadedmodule로 변경했습니다.
— 하워드

45

나는 같은 문제가 있었다. 이 경우 imports [...]가져 오지 않으면 작동하지 않으므로 매우 중요 NgbModalModule합니다.

오류 설명에 따르면 구성 요소를 entryComponents배열에 추가해야하며 분명하지만 처음에이 구성 요소를 추가 했는지 확인하십시오.

imports: [
    ...
    NgbModalModule,
    ...
  ],

6
당신은 저를 구 했어요 건배! 이것은 모달에서 컴포넌트를 열려고 할 때 분명히 필요합니다. 이 상황에서는 오류 메시지가 약간 잘못 표시됩니다.
— beawolf

어디서 가져 오나요?
— Mdomin45

내 경우에는, NbDialogModule.forChild (널)에 NbDialogModule의 수입을 변경
— 마얀 희망을

'@ ng-bootstrap / ng-bootstrap'에서 @ Mdomin45 import {NgbModalModule};
— mpatel

24

앱 모듈의 @NgModule에있는 entryComponents에 해당 컴포넌트를 추가하십시오.

entryComponents:[ConfirmComponent],

뿐만 아니라 선언 :

declarations: [
    AppComponent,
    ConfirmComponent
]

내 하루를 구했다! 건배 친구
— Sahan Serasinghe

ModalComponent 를 호출하는 내 구성 요소 는 구성 요소의 손자입니다. 어느 쪽도 아니 추가하지 ModalComponent 로를 entryComponents도에 추가 exports날 위해 일했습니다. 그러나 나는 손자가 아닌 다른 구성 요소에서 ModalComponent 를 호출 할 수 있습니다
— canbax

14

가져 오기에 'NgbModalModule'을 추가하고 아래에 표시된대로 entryComponents App.module.ts에 컴포넌트 이름을 추가하십시오. 여기에 이미지 설명을 입력하십시오


ModalComponent 를 호출하는 내 구성 요소 는 구성 요소의 손자입니다. 어느 쪽도 아니 추가하지 ModalComponent 로를 entryComponents도에 추가 exports날 위해 일했습니다. 그러나 나는 손자가 아닌 다른 구성 요소에서 ModalComponent 를 호출 할 수 있습니다
— canbax

구성 요소가 이미 entryComponents에 추가되었지만 여전히 문제가 발생하는 경우이 답변을 반복해야합니다. 사용중인 modalComponent를 확인하고 imports 배열에 추가하십시오! 이것은 내 생명을 구했습니다!
— Clyde

10

@NgModuledecorator 함수에서 entryComponents에 동적으로 작성된 컴포넌트를 배치하십시오.

@NgModule({
    imports: [
        FormsModule,
        CommonModule,
        DashbaordRoutingModule
    ],
    declarations: [
        MainComponent,
        TestDialog
    ],
    entryComponents: [
        TestDialog
    ]
})

1
그렇습니다. 이것은 매우 유용했습니다. 경로에 의해 선택되지 않고 동적으로 사용되는 대화 상자를 말한 경우, entryComponents선언 된 각 ng 모듈에 추가해야합니다 .
— atconway

ModalComponent 를 호출하는 내 구성 요소 는 구성 요소의 손자입니다. 어느 쪽도 아니 추가하지 ModalComponent 로를 entryComponents도에 추가 exports날 위해 일했습니다. 그러나 나는 손자가 아닌 다른 구성 요소에서 ModalComponent 를 호출 할 수 있습니다
— canbax

10

각도 6과 동일한 문제가 있습니다.

@NgModule({
...
entryComponents: [ConfirmComponent],
providers:[ConfirmService]

})

ConfirmService 와 같은 서비스가있는 경우 루트 대신 현재 모듈의 공급자에서 선언해야 합니다


8

부트 스트랩 모달에 대해 동일한 문제가있었습니다.

'@ ng-bootstrap / ng-bootstrap'에서 {NgbModal} 가져 오기;

이 경우 다른 응답이 제안하는 것처럼 구성 요소를 모듈 선언 및 entryComponents에 추가하고 모듈에 추가하십시오.

'@ ng-bootstrap / ng-bootstrap'에서 {NgbModule} 가져 오기;

imports: [
   NgbModule.forRoot(),
   ...
]

8

이 오류는 구성 요소를 동적으로로드하려고 할 때 발생합니다.

  1. 로드하려는 구성 요소가 라우팅 모듈이 아닙니다
  2. 구성 요소가 모듈 entryComponents에 없습니다.

라우팅 모듈에서

const routes: Routes = [{ path: 'confirm-component', component: ConfirmComponent,data: {}}]

또는 모듈

entryComponents: [
ConfirmComponent
} 

이 오류를 해결하기 위해 라우터를 구성 요소에 추가하거나 모듈의 entryComponents에 추가 할 수 있습니다.

  1. component에 라우터를 추가하십시오.이 접근 방식의 단점은 해당 URL로 구성 요소에 액세스 할 수 있다는 것입니다.
  2. entryComponents에 추가하십시오. 이 경우 구성 요소에 연결된 URL이 없으며 URL로 액세스 할 수 없습니다.

8

동적 구성 요소를 만들 때 Angular7에서 동일한 문제가 발생했습니다. 동적으로로드해야하는 두 가지 구성 요소 (TreatListComponent, MyTreatComponent)가 있습니다. 방금 app.module.ts 파일에 entryComponents 배열을 추가했습니다.

    entryComponents: [
    TreatListComponent,
    MyTreatComponent
  ],

6

응용 프로그램에서 라우팅을 사용하는 경우

라우팅 경로에 새 구성 요소 추가

예를 들면 다음과 같습니다.

    const appRoutes: Routes = [
  { path: '', component: LoginComponent },
  { path: 'home', component: HomeComponent },
  { path: 'fundList',      component: FundListComponent },
];

7
아니요, 모든 구성 요소가 경로에 있어야한다고 생각하지 않습니다.
— Mcanic

표시하려는 페이지 만 경로에 있어야합니다. 페이지는 여러 구성 요소를 사용 / 표시 할 수 있습니다
— Thibaud Lacan

모달과 같이 컴포넌트를 Route에 추가 할 필요가 없을 때마다. @NgModuledecorator 함수에서 entryComponents에 동적으로 작성된 컴포넌트를 배치하십시오.
— CodeMind

3

필자의 경우 entryComponents가 전혀 필요하지 않았습니다. 아래 링크에 설명 된 기본 설정 만 있지만 주 앱 모듈과 인클로저 모듈 모두에 가져 오기를 포함해야했습니다.

imports: [
    NgbModule.forRoot(),
    ...
]

https://medium.com/@sunilk/getting-started-angular-6-and-ng-bootstrap-4-4b314e015c1c

컴포넌트가 모달에 포함될 경우에만 entryComponents에 추가해야합니다. 문서에서 :

기존 구성 요소를 모달 창의 컨텐츠로 전달할 수 있습니다. 이 경우 컨텐츠 컴포넌트를 NgModule의 entryComponents 섹션으로 추가해야합니다.


error TS2339: Property 'forRoot' does not exist on type 'typeof NgbModule'.각도 8 사용
— canbax

3

동적 구성 요소를 사용하는 ag-grid와 동일한 문제가 발생했습니다. 동적 구성 요소를 ag-grid 모듈에 추가해야한다는 것을 발견했습니다.

수입품 : [StratoMaterialModule, BrowserModule, AppRoutingModule, HttpClientModule, BrowserAnimationsModule, NgbModule.forRoot (), FormsModule, ReactiveFormsModule, AppRoutingModule, AgGridModule.withComponents (ProjectUpdateButtonComponent) ],


3

필자의 경우 MatDialogModule하위 모듈에서 가져 오기에 추가 하는 것을 잊었습니다 .


2

설명을 원하시면 여기를 클릭하십시오. ComponentFactoryResolver구성 요소에서 직접 사용하지 않고 서비스로 추상화하려는 경우 구성 요소에 삽입하면 지연로드 된 경우 작동하지 않으므로 해당 모듈의 공급자 아래에로드해야합니다.


2

에서 구성 요소 대화 상자 클래스를 제공 한 후에도 여전히 오류가 발생 entryComponents하면 다시 시작해보십시오 ng serve.


2

내 오류는 .html에서 잘못된 매개 변수로 NgbModal open 메소드를 호출하는 중입니다.


2

다음 NgbModule과 같이 모듈 에서를 가져와야합니다 .

@NgModule({
  declarations: [
    AboutModalComponent
  ],
  imports: [
    CommonModule,
    SharedModule,
    RouterModule,
    FormsModule,
    ReactiveFormsModule,
    NgxLoadingModule,
    NgbDatepickerModule,
    NgbModule
  ],
  entryComponents: [AboutModalComponent]
})
 export class HomeModule {}



1
  1. entryComponents중요합니다. 위의 답변은 정확합니다.

그러나...

  1. 모달 (공통 패턴)을 여는 서비스를 제공하고 대화 상자 컴포넌트를 정의하는 모듈이 AppModule에로드되지 않은 경우로 변경 providedIn: 'root'해야 providedIn: MyModule합니다. 일반적으로 providedIn: SomeModule모듈에있는 모든 대화 서비스에 대해를 사용해야합니다 .

0

Angular8을 사용하고 있으며 다른 모듈을 동적으로 구성하여 구성 요소 를 열려고합니다 .이 경우 import the module구성 요소 뿐만 아니라 구성 요소를 열려고하는 모듈 export에 entryComponents배열을 나열해야합니다. 이전 답변이했던 것처럼.

imports: [
    ...
    TheModuleThatOwnTheTargetedComponent,
    ...
  ],

0

제 경우 나이 문제 해결 :
배치 1) NgxMaterialTimepickerModule에 app module imports:[ ]
배치 2) NgxMaterialTimepickerModule에 testmodule.ts imports:[ ]
배치 3) testcomponent하여 declartions:[ ]및entryComponents:[ ]

(각 8 + 버전을 사용하고 있습니다)


-1

app.module의 모든 새 페이지를 선언하십시오.

@NgModule({
  declarations: [
    MyApp,
    RegisterPage,
    OtpPage,
    LoginPage,
    ForgetPasswordPage,ChatlistPage,ChatPage,TabsPage

    // AboutPage,

    // BusinessDetailDescPage,
    // BusinessDescPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot(),
    HttpClientModule,
    NgxBarcodeModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    RegisterPage,
    OtpPage,
    LoginPage,
    ForgetPasswordPage,ChatlistPage,ChatPage,TabsPage
    // AboutPage,

    // BusinessDetailDescPage,
    // BusinessDescPage
  ],

 - 


----------


---------

당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.