Search code examples
angularangular-materialangular7angular-forms

Difference between Template Driven Form and Reactive Form using a service


I would like to know when should I use a template driven form instead of a Reactive form. I know the theory based in that question(What are the practical differences between template-driven and reactive forms?) but I don't know which one use with Angular Material. I always have doubts about which use.

Could anyone help me please?

Thank you in advance.


Solution

  • As an Angular focused developer I recommend always using reactive form setups.

    Developers will argue but trust me you will be saving yourself headaches later. Netanel B wrote about it here too: Why It’s Time to Say Goodbye to Angular Template-Driven Forms

    Let's say you want a very simple input, you may be tempted to simply use

    • ngModel
    • template variables
    • @ViewChild

    They may be fine, for now.

    But let's say you need to add:

    • Validation
    • Watching for changes
    • Updating the value programmatically

    These all require you rely on and code around the method you've chosen to access the input.

    Where Reactive forms are a pre-built API which brings a standard to each need.