I got this question in one of my tech Facebook groups today:
In Angular2, Is there anyway for dealing with forms rather than
formtag??? As In AngularJS 1.x, there was
Is there something like that in Angular2 or we must deal with form tag?!
And the answer is: Yes. It’s possible to create forms without the
form tag in Angular 2, with a gotcha…
Template Driven Forms
If you look for the selector for ngForm directive in Angular2, you’ll find it like that:
Note that last one. Any element with
<ngForm ...> or attribute
<any ngForm ... > should work.
Reactive Forms (Model Driven)
The selector for formGroup directive is:
Which also means that any element with
formGroup attribute should work.
There is a relatively-big bug with non-form elements used as forms in Angular 2. The submit events do not work.
The implementation is just not as mature as Angular 1.
I have raised a bug here in March, but it’s probably a low priority:
You might be able to comment on it stating your scenario to bring it some attention.
P.S. Please help me out by checking this offer, then look below for a small Thank You.
How did I learn that?
As a bonus for coming here, I'm giving away a free newsletter for web developers that you can sign up for from here.
It's not an anything-and-everything link list. It's thoughtfully collected picks of articles and tools, that focus on Angular 2, ASP.NET 5, and other fullstack developer goodies.