Hi

As per the documentation, `tap` returns `void` it is designed to perform
side Effects (like modifying a global state such as sessionStorage).
if you subscribe to `getUsers` you will have access to the response:
```
public ngOnInit() {
  this.getUsers().subscribe(res => {
    console.log(res.userRole);
  })
}
```

Alternatively, you can store the response on the controller:

```
public getUsers(): Observable<user[]> {
  return this.http.get().pipe(
    tap(res => {
      sessionStorage.setItem('userRole', res.userRole);
      this.roles = res.userRole;
    })
  )
}
```

Hope this helps ;)

*Bastien Lemaire*


On Mon, 21 Nov 2022 at 09:38, JD Lambert <joelambert1...@gmail.com> wrote:

> I am having difficulty grasping some of the concepts. Such as I have
> created a subscription to my SQL DB (users) upon login and I am able to
> present the data on the page (DOM). However, I a now trying to pull out
> specific data from the item to save for later use in my typescript file.
>
> *login.component.ts*
>
> this.usersService.getUsers() .subscribe((result: users) => (this.users[0]
> = result));
>
> *users.service.ts*
> public getUsers() : Observable<user[]> {
>      let userEmail = sessionStorage.getItem('userEmail');
>      return this.http.get<user
> []>(`${environment.apiUrl}/${this.url}/${userEmail}`).pipe(
>       tap((res:any)=>{
>         sessionStorage.setItem('userRole', res.userRole;
>         })
>      );
>
> This returns as expected and fills the following html.
>
> *login.component.html*
> <div class="row" style="background-color:transparent;"> <mat-card
> *ngFor="let user of user" class="ecard">
> <mat-card-title>{{user.role}}</mat-card-title> </mat-card> </div>
>
> However, I would like to use information from the 'user' to perform other
> functions in the ts file.
>
> The TAP function is returning undefined and I do not understand why or how
> to correct this?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Angular and AngularJS discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to angular+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/angular/2313a684-6bf9-49cc-8ba5-985234395fa5n%40googlegroups.com
> <https://groups.google.com/d/msgid/angular/2313a684-6bf9-49cc-8ba5-985234395fa5n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/angular/CAJ7E9zE_2hFj0N28wNxz1NKTBVUZrh%2BSgNKHJU%2Badp_5_brKQg%40mail.gmail.com.

Reply via email to