Search code examples
angularangular-formsangular-module

Forms Module not found in Child module


I am trying to use ReactiveFormsModule. I imported it in app.module. My component is in child module, but child module not able to get that.

Should I want to import this module in each child modules? Or is there any way to keep it in appmodule and make it work in all child modules?


Solution

  • That's the way how encapsulation in Angular works.

    It prevents from invisible dependencies and makes it very clear what the module needs. How you could approach it, is by creating a SharedModule, which contains all necessary modules to import it into the respective module.

    This is a very common behavior. For an example you can have a look here: how to use parent module component in child module component in angular2