What is entryComponents in angular ngModule?

前端 未结 6 1778
[愿得一人]
[愿得一人] 2020-12-04 06:31

I am working on an Ionic app ( 2.0.0-rc0 ) which depends on angular 2 . So the new introduction of ngModules is included.

6条回答
  •  無奈伤痛
    2020-12-04 07:18

    The other answers mention this but the basic summary is:

    • its needed when a Component is NOT used inside an html template
    • For example when using Angular Material dialog components you use the component indirectly.

    Material dialog components are created inside the TS code and not the template:

        const dialogRef = this.dialog.open(MyExampleDialog, { width: '250px' });
      }
    

    This requires you to register it as an entryComponent:

    • entryComponents: [MyExampleDialog]

    Otherwise you get a error:

    • ERROR Error: No component factory found for MyExampleDialog. Did you add it to @NgModule.entryComponents?

提交回复
热议问题