Home > Software design >  Angular Reactive Forms vs ngModel, which has better performance?
Angular Reactive Forms vs ngModel, which has better performance?

Time:12-24

I am trying to understand which of the two have better performance, I guess the type of form is important for the response, in my case I am trying to create some ControlValueAccessor components that contain a mat-autocomplete field each, the goal is to use it inside a bigger reactive form element, I would like to use the reactive form implementation in the ControlValueAccessor components but I don't know if it negatively affects performance and maybe it is better to have ngModel inside the reactive form

CodePudding user response:

Angular Forms

There is no noticeable difference in performance. You shouldn't base your choice on it.

Template Forms

Template forms, while easy to use, are rather difficult to unit test. Angular will just generate the model for you. This is done during transpiling, so it does not affect the performance in production.

Model Forms

Compared to template forms, model forms (or reactive forms) are easier to test in your unit tests. You will have to create the model yourself. This leads to more code in your component.ts file.

My Thoughts

In other words, if you plan to test or have special needs for your form, you might want to use reactive forms.

If you are not planning to write tests, your needs for the form are rather basic or the overall skill of using angular in your team is rather low, maybe pick the simple solution and use template forms.

  • Related