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<form>and<ng-form>.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…
Here’s how:
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 tag <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.
Gotcha
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.
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 (4.x/MVC5 and Core), and other fullstack developer goodies.
Take it for a test ride, and you may unsubscribe any time.
You might also want to support me by checking these out [Thanks]: