Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular importing FormsModule in app.module vs child.module

I'm using Angular with lazy loading modules. Each component has its own module. If I import a module in the root module (app.module) it must work fine. For example, I imported HttpClientModule in app.module and can use it in child components.

But about FormsModule, this doesn't work fine. I must import it in the child module, otherwise, I get the following errors:

Can't bind to 'ngModel' since it isn't a known property of 'input'. ("

Do you have any idea why this happens?
like image 736
Vahid Najafi Avatar asked Jun 09 '26 13:06

Vahid Najafi


1 Answers

I found the answer here:

  • if the module is imported for components, you’ll need to import it in each module needing them,
  • if the module is imported for services, you’ll need to import it only once, in the first app module.
like image 128
Vahid Najafi Avatar answered Jun 12 '26 01:06

Vahid Najafi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!