In AngularJS, is there any way to declare ng-model directly on the <form> element instead of having to do it on every single control/input of that form and then be able to access the values of the controls in the controller through their names?
Specifically, if you have a form like this,
<form>
<input type="text" name="email">
<input type="text" name="age">
</form>
typically, you'd do something like this,
<form>
<input type="text" ng-model="user.email">
<input type="text" ng-model="user.age">
<form>
which then gives you access to the user object and its properties in the controller:
$scope.user
$scope.user.email
$scope.user.age
I would like to do something like this instead:
<form ng-model="user">
<input type="text" name="email">
<input type="text" name="age">
</form>
and then be able to access the values in the controller:
$scope.user.email
$scope.user.age
The reason I'm asking is that I'm angularizing an existing web project and some of the forms have easily 20 or 30 controls and defining the ng-model individually seems like an overkill.
All the form examples that I'm able to find declare the ng-model on the individual controls. I was also able to dig up this ticket which basically says that something like this would require a major AngularJS overhaul, so I suspect it may not be possible. But the ticket is from a year ago and perhaps things have changed since then.