Flavio boa noite,
Estou tentando o seguinte codigo para estudo de possibilidades.
codigo:
import { Injectable } from "@angular/core";
import { TokenService } from "../token/token.service";
import { Subject } from "rxjs";
import { AuthService } from "../auth.service";
@Injectable({ providedIn: 'root'})
export class UserService {
private userSubject = new Subject<any>();
constructor(private tokenService: TokenService,
private authService: AuthService){
this.tokenService.hasToken();
this.Notify();
}
setToken(token: string){
}
getUser(){
return this.userSubject;
}
private Notify(){
const resultado = this.authService.retorno;
const user = resultado as any;
this.userSubject.next(user);
console.log(user);
}
}
ate aqui tudo bem. Porem quando eu tento passar o get user para ter acesso ao Obsevable, que esta da seguinte forma:
import { Component, OnInit } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { UserService } from '../../../core/user/user.service';
import { Observable } from 'rxjs';
import { User } from '../../../core/user/user';
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent {
pushRightClass: string = 'push-right';
user$: any;
user:any = [];
constructor(private translate: TranslateService, public router: Router,
userService: UserService) {
this.user$ = userService.getUser();
this.user$.subscribe(user => this.user = user);
console.log(this.user);
O objeto esta vazio... Segue console:
81dc9bdb52d04dc20036dbd8313ed055
auth.service.ts:40 N
auth.service.ts:50 005320001520170517
user.service.ts:41 {codigo: 532, nome: "FINANCEIRO", login: "FINANCEIRO.BEF", flagAtivo: "S", flagAdministrador: "N", …}
header.component.ts:26 []
Poderia ajudar por favor...
Obrigado.