0

How to ng-model a field on AngularJS form for the entity which has One-to-Many relationship-

For Ex;- User Entity(name, contact, addressList) has Address(flatNumber, streetAddress) entity.

User{ name: contact: Address{ flatNumber: streetAddress: } }

Now in AngularJS form for name input text i put user.name and its value is populated by setter, same for Address i put a addressList with OneToMany relationShip. so for input field flatnumber, what should i write in ng-model, Tried user.address.flatNumber but it is not retaining anything. The JSON has only primitive attributes of user class, not the dependency values.

Please suggest if there isany example i can refer for one-to-many relationship using AngularJS form

Developer1001
  • 63
  • 1
  • 8
  • 1
    Just don't try to do that. Entities represent your persistence model. Not your JSON API inputs. Bind your form to a DTO class specifically designed to match with what the form submission contains. Then do whatever you need to do with that input (like creating and populating a new entity). – JB Nizet May 09 '19 at 09:35
  • Actually the issues is that when i have a foreign key in my dependency, saving parent should save the child also, but i am not sure how my child attributes will be populated ? – Developer1001 May 09 '19 at 10:31
  • I also edited my question for more clarity – Developer1001 May 09 '19 at 10:43
  • Right now your question is so vague that I can't even tell if you have an AngularJS issue, or a backend REST framework issue, or a JPA issue. If you have some code that doesn't work as you think it should, then post it, tell precisely what you're doing, what you expect to happen, and what happens instead. With concrete code, inputs and outputs. – JB Nizet May 09 '19 at 13:52
  • Hey @JBNizet, Please see this link https://stackoverflow.com/questions/56154426/onetomany-mapping-on-angularjs-page – Developer1001 May 15 '19 at 17:11

0 Answers0