V
V
vit gray2019-02-15 15:45:23
Angular
vit gray, 2019-02-15 15:45:23

How to change data in locale storage Angular?

{id: 3; email: "789456123" firstName: "789456123" lastName: "789456123" phone: "789456123"
token: "fake-jwt-token"} this is how they are saved.
delete like this:
home.component.html

<button type="button" class="btn btn-primary" (click)="deleteUser(user.id)">Delete</button>

home.component.ts
deleteUser(id: number) {
        this.userService.delete(id).pipe(first()).subscribe(() => {
            this.loadAllUsers()
        });
    }
    private loadAllUsers() {
        this.userService.getAll().pipe(first()).subscribe(users => {
            this.users = users;
        });
    }

user.service.ts
delete(id: number) {
        return this.http.delete(`${environment.apiUrl}/users/${id}`);
    }
}

when registering, I wrote down this data in the locale.
I figured out the removal, but I don’t know how to edit the existing data.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Semenov, 2019-02-18
@w4_alex

You get data from local Storage, make changes, delete and write again, by and large, you can not delete it, it will overwrite the data with the same key.
Moreover, why edit authorization data?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question