简体   繁体   English

无法在 MatDialog 中使用来自其他模块的组件

[英]Cannot use component from other module in MatDialog

I have two modules, AModule and BModule.我有两个模块,AModule 和 BModule。

AModule declares and exports a component, called ProductCardComponent, which has one input, which is AModule 声明并导出一个名为 ProductCardComponent 的组件,它有一个输入,即

@Input() product: ProductModel

Now in BModule I import AModule and I'm opening a MatDialog which tries to render the product card as such:现在在 BModule 中,我导入了 AModule 并打开了一个 MatDialog,它试图将产品卡呈现为:

<app-product-card [product]="product">

However, I get the error Can't bind to 'product' since it isn't a known property of 'app-product-card'.但是,我收到错误Can't bind to 'product' since it isn't a known property of 'app-product-card'. If I remove the binding, the component doesn't render at all, which gives me the impression that it simply cannot find the component.如果我删除绑定,则该组件根本不会呈现,这给我的印象是它根本找不到该组件。 I can use it in other places alright.我可以在其他地方使用它。

What am I missing here?我在这里缺少什么?

UPDATE: as I was fiddling around I realised other things like *ngFor and async also didn't work, as if the component wasn't in any module declaration, but still functioned.更新:当我在摆弄时,我意识到*ngForasync类的其他东西也不起作用,就好像该组件不在任何模块声明中,但仍然起作用。 I then realised the module was lazy loaded.然后我意识到该模块是延迟加载的。 I added BModule to the imports of my main AppModule, and behold, it all started functioning!我将 BModule 添加到我的主 AppModule 的导入中,看哪,它都开始运行了!

正如我所看到的,您使用的是不同的模块 A 和 B。在这种情况下,这将不起作用,您应该使用要使用的组件创建一个共享模块,导出这些组件,然后在其他模块中导入共享模块

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法将一个模块中的组件用于另一个模块组件 - I cannot use component from one module into another module component Angular 6 - MatDialog - EventEmitter - 从 MatDialog 将对象共享给父组件 - Angular 6 - MatDialog - EventEmitter - share object to parent component from MatDialog 如何在angular中使用单个组件作为页面和MatDialog - How to use single component as page and MatDialog in angular 使用没有MatDialog,MatDialogRef的组件<SomeComponent> - use component without MatDialog, MatDialogRef<SomeComponent> 使用自定义类中的 Angular MatDialog(不包含在 app.module.ts 中) - Use Angular MatDialog from custom class (not included in app.module.ts) Angular:无法在来自不同模块的组件中使用在应用模块中导入的模块 - Angular: Cannot use module imported in app module in a component from a different module 我如何将延迟加载模块中的组件用作其他未延迟加载的组件中的子组件? - How can i use component from lazy loaded module as child in other component which is not lazy loaded? 如何在 AppComponent 以外的其他组件中使用从共享模块导入的 Angular 组件 - How can I use angular component imported from a shared module in another component other than AppComponent MatDialog Angular打开组件? - MatDialog Angular open component? 如何从 MatDialog =&gt; Rxjs Effect =&gt; Component 传递数据? - How do I pass data from MatDialog => Rxjs Effect => Component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM