I've set up 2 routes in my Angular 7 application,
{
path: 'create',
component: CreateComponent
},
{
path: 'view',
component: ViewComponent
}
Both of these routes are lazily loaded. The CreateComponent
contains a form with several form fields, and the same goes for the ViewComponent
.
The issue I'm facing is that when I navigate from the /create
route or CreateComponent
to the /view
route or ViewComponent
, all the form fields within the previous component (i.e. ViewComponent
) get reset to their initial state (confirmed by returning to the /create
route). This means that the form fields are automatically reset by Angular. The same problem occurs if I switch from the /view
route to the /create
route, causing all form fields in /view
to be reset automatically.
How can I resolve this issue? I want the form fields to retain their previous values (even if the form hasn't been submitted yet) when navigating to other routes.
Thank you.