My Form includes validation as shown below:
<form [formGroup]="LoginForm">
First name:<br>
<input type="text" formControlName="firstname" >
<br>
Last name:<br>
<input type="text" formControlName="lastname">
<button type="submit" [disabled]="!this.LoginForm.valid"></button>
</form>
component.ts
LoginForm: FormGroup;
onloginUser() {
this.LoginForm = this.form.group({
firstname: ['', Validators.required],
lastname: ['', Validators.required],
})
}
I implemented a local storage service with the following code,
this.storage.set("user_data",this.LoginForm.value);
this.storage.get("user_data");
The issue I am facing is that when a user reloads the page or navigates back/forward, the data should remain in the input fields. However, the above code is not achieving this.
I have already checked the suggestions on stackoverflow at the following link: link, but none of the answers provided a solution for my specific case. Can anyone offer a better answer that would be helpful to me?