Angular2 材质对话框有问题 - 您是否将其添加到 @NgModule.entryComponents? [英] Angular2 material dialog has issues - Did you add it to @NgModule.entryComponents?
问题描述
我正在尝试遵循 https://material.angular.io/components/上的文档组件/对话框,但我不明白为什么会出现以下问题?
I am trying to follow the docs on https://material.angular.io/components/component/dialog but I cannot understand why it has the below issue?
我在我的组件上添加了以下内容:
I added the below on my component:
@Component({
selector: 'dialog-result-example-dialog',
templateUrl: './dialog-result-example-dialog.html',
})
export class DialogResultExampleDialog {
constructor(public dialogRef: MdDialogRef<DialogResultExampleDialog>) {}
}
在我的模块中我添加了
import { HomeComponent,DialogResultExampleDialog } from './home/home.component';
@NgModule({
declarations: [
AppComponent,
LoginComponent,
DashboardComponent,
HomeComponent,
DialogResultExampleDialog
],
// ...
但我收到此错误....
Yet I get this error....
EXCEPTION: Error in ./HomeComponent class HomeComponent - inline template:53:0 caused by: No component factory found for DialogResultExampleDialog. Did you add it to @NgModule.entryComponents?
ErrorHandler.handleError @ error_handler.js:50
next @ application_ref.js:346
schedulerFn @ async.js:91
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:77
NgZone.triggerError @ ng_zone.js:329
onHandleError @ ng_zone.js:290
ZoneDelegate.handleError @ zone.js:246
Zone.runTask @ zone.js:154
ZoneTask.invoke @ zone.js:345
error_handler.js:52 ORIGINAL EXCEPTION: No component factory found for DialogResultExampleDialog. Did you add it to @NgModule.entryComponents?
ErrorHandler.handleError @ error_handler.js:52
next @ application_ref.js:346
schedulerFn @ async.js:91
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:77
NgZone.triggerError @ ng_zone.js:329
onHandleError @ ng_zone.js:290
ZoneDelegate.handleError @ zone.js:246
Zone.runTask @ zone.js:154
ZoneTask.invoke @ zone.js:345
推荐答案
Angular 9.0.0 <
从 Ivy 9.0.0 开始,不再需要 entryComponents 属性.请参阅弃用指南.
Since 9.0.0 with Ivy, the entryComponents property is no longer necessary. See deprecations guide.
Angular 9.0.0 >
您需要将动态创建的组件添加到 @NgModule
You need to add dynamically created components to entryComponents
inside your @NgModule
@NgModule({
declarations: [
AppComponent,
LoginComponent,
DashboardComponent,
HomeComponent,
DialogResultExampleDialog
],
entryComponents: [DialogResultExampleDialog]
注意:在某些情况下,延迟加载的模块下的entryComponents
将不起作用,作为一种变通方法,将它们放入您的应用程序中.模块
(root)
Note: In some cases entryComponents
under lazy loaded modules will not work, as a workaround put them in your app.module
(root)
这篇关于Angular2 材质对话框有问题 - 您是否将其添加到 @NgModule.entryComponents?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!