My Objective:
The framework I'm currently using generates input names based on a specific convention. Here is an example of the generated input names within my form structure for a scenario where a "Class has many Students":
name="data[Class][name]"
name="data[Student][0][name]"
name="data[Student][1][name]"
Now, I am facing a challenge in reflecting this structure in my angular $scope.
I anticipate that the same structure will manifest in $scope.data as shown below:
$scope.data: {
Class: {
name: 'Some Name',
},
Student: [
{
name: 'Some Name'
},
/* ... */
]
}
Approaches Taken:
I attempted giving the form the name "data" assuming it would create another scope and the fields would appear within that scope. Subsequently, I utilized ng-model="data.Model.field"
for each field. However, the result was not as expected. The console displayed an object like this:
Jc { $error={...}, $name="formData", $dirty=false, more...}
This seems to be the angular form handler, but I couldn't find a way to access my form's data or transform it into the desired structure.
Furthermore, the multitude of different approaches to form handling in Angular left me feeling puzzled and lost.
- Is achieving my desired outcome possible?
- Does my goal even make sense?
- If so, how can I accomplish it?
- If not, what is the best approach to handling forms?