[英]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.更新:当我在摆弄时,我意识到*ngFor
和async
类的其他东西也不起作用,就好像该组件不在任何模块声明中,但仍然起作用。 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.