Reputation: 3914
After login I get user
private login() {
let data = { "UserName": "admin" , "Password": "+" };
this.apiService.doLogin(data).subscribe(
(res) => this.userService.set('user', res),
(err) => console.log(err)
)
}
How I can implement this userService? * I want get some user data without new call to back end? ** I know about https://github.com/ngrx/store, maybe someone know better solution?
Upvotes: 1
Views: 816
Reputation: 9178
If you want to storage your logged user details, you can do this in few ways.
Redux store (ngrx):
You could use ngrx store concept - https://github.com/ngrx/store. When you get your user model from backend, you just have to dispatch an action to load data.
Advantages:
Service:
Also, you could store your user model object in service as a private variable.
Disadvantages:
Upvotes: 2
Reputation: 55443
HTML5localSorage can be used but for Angular2, ngrx/store is better. It also provides state management so its recommended to use it.
Upvotes: 0