Hi,
I get error in the below code:
onSubmit() {
console.log(this.registerationForm.value);
this.user = Object.assign(this.user, this.registerationForm.value);
localStorage.setItem('Users', JSON.stringify(this.user));
}
addUser(user: any){
let users: any = [];
if (localStorage.getItem('Users'))
{
users = JSON.parse(localStorage.getItem('Users'));
users = [user, ...users];
}
else
{
users = [user];
}
localStorage.setItem('users', JSON.stringify(users));
}
error in this line:
users = JSON.parse(localStorage.getItem('Users'));
the error is:
Argument of type 'string | null' is not assignable to parameter of type 'string'.
Type 'null' is not assignable to type 'string'.