DEV Community

David Garcia
David Garcia

Posted on

🚀 A Better Alternative to .get() in Angular Forms

If you’re using form.get('field') to access a control in a FormGroup, you’re not alone. It’s the most common approach, but there’s a safer and more type-friendly alternative.

💡 Why use .controls instead of .get()?
**
✅ **Type Safety
– .controls returns the exact type (FormControl, FormGroup, etc.), eliminating unnecessary type assertions.

✅ Easier Access to Methods – With a FormArray, for example, you can directly use form.controls.items.push(...).

✅ Better Intellisense – Your IDE will autocomplete control names accurately.

🔹 A small change that makes a big difference in your code. Do you use it, or are you still sticking with .get()? 💬

Top comments (0)