2

I have a directive, which is not standalone. I am trying to use this directive inside Standalone component. while doing it, I am getting below error.

enter image description here

I have included directive inside component's import array, enter image description here

Question is: Can we use non-standalone directives inside standalone components?

Keval Patel
  • 161
  • 1
  • 15

2 Answers2

3

Mike's comment gave me hint to create a parent module and import it wherever require.

I have created 1 parent DirectiveModule, where I mentioned PositiveIntegersDirective inside Exported and Declaration array.

Now I have imported DirectiveModule inside my standalone component. and it worked... !

enter image description here

Keval Patel
  • 161
  • 1
  • 15
2

That error you get is a little weird since I get a different one when attempting to import a non-standalone directive into a standalone component:

https://stackblitz.com/edit/angular-ivy-xsdtcl?file=src/app/test.component.ts

The directive 'TestDirective' appears in 'imports', but is not standalone and cannot be imported directly. It must be imported via an NgModule.

... which basically states that the directive you're importing must either be standalone itself or be part of a module that must be imported instead (since the non-standalone directive must still be declared).