Home > other >  Angular selector is not a known element: if it's an Angular component, then verify that it is p
Angular selector is not a known element: if it's an Angular component, then verify that it is p

Time:10-14

I created a component and tried to use it in another component by declaring a selector in the display part.

<app-component1></app-component1>

But I get a compile error. I checked the imports in the modules, everything is fine, there are no errors. Can't figure out what is the reason why I can't use the component? Here is stackblitz example of my app.

https://stackblitz.com/edit/angular-ivy-uve2pn?file=src/app/app.module.ts

CodePudding user response:

Maybe the module that you import doesn't have an export for component that you are looking for?

When you e.g have a component let's say ComponentA in ModuleA, to use ComponentA in other ModuleB, you need to have in Modul A

declarations: [ComponentA]
exports: [ComponentA]

CodePudding user response:

I fixed the code by converting modules to regular components and declaring them in blocks "declarations" and "exports" in app.module

  • Related