I have a form below that I am trying to save. Please review my HTML code for the form.
HTML
<form ng-submit="save()">
<input type="text" ng-model="user.name"/>
<input type="text" ng-model="user.age"/>
<input type="text" ng-model="user.homenumber"/>
<input type="text" ng-model="user.road"/>
<input type="text" ng-model="user.city"/>
<input type="text" ng-model="user.school"/>
<button type="submit">Save </button>
</form>
I used the following function to save the form data:
$scope.save = function (){
console.log($scope.user)
}
The result after saving looks like this:
{ name:"dais",
age:"24",
"homenumber":"23",
"road":"new road",
"city":"colombo",
school:"new school"
}
However, I need to save the form as a JSON object in the requested format:
Requested format:
{name:"dais",
age:"24",
"address":{
"homenumber":"23",
"road":"new road",
"city":"colombo"
},
school:"new school"
}
Can someone help me modify my save function to achieve this?