I am developing an AngularJS 1 (+ Ionic + ui-router) single page app. Among other things, the app lets 'CRUD' employees and companies.
I am struggling with the "edit employee" page. This page shows fields for first and last name, and has a button to select the company in which the employee works. When the button is clicked, a new view is opened, listing all the existing companies. The user can then select one in order to assign it to the employee, and get back to the former screen (employee edit), which then displays (read-only) the name of the company.
My issue is that when getting back to the 'edit employee' view, its controller is reloaded, and thus the changes made to first and last names are lost, because the controller starts with loading the employee information from the database.
To summarize what happens:
To persist form's state you can use a service. When edit form scope is destroyed with some unsaved changes, you just save this data to service. Inside this service you can even store it to local storage to keep data after page refresh.
But the better way is to have simple drop down on edit form. If there's too much information, you can use modals or like that.