0
export class Component implements OnInit {
obj:string;
img:string;
username:string = '';
email:string;
bio:string;

constructor(private authService:AuthService) { 
  this.authService.user
  .subscribe((userVal) => {
   this.obj = JSON.stringify(userVal);
    this.username = userVal.username;
    console.log(this.username);
  })
}

Now this doesn't work, you can log the response but not display it in the component view

You can find a few hack like this here: Angular 6 View is not updated after changing a variable within subscribe

None of the options seem to work that are presented here

Anyone got a solution? If its not possible with any clear way then Angular is doomed

Lajos Bela
  • 49
  • 6
  • Can you please share your template file? – Mir entafaz Ali Jul 29 '21 at 15:11
  • The BehaviorSubject subject method should work. Sample stackblitz- https://stackblitz.com/edit/angular-ivy-uazqj1?file=src%2Fapp%2Fservice.ts – MBB Jul 29 '21 at 15:14
  • You said "This doesn't work" but I do not understand what you were trying to do, or why it didn't work. – JeffryHouser Jul 29 '21 at 17:27
  • Hey MBB, It works with BehaviourSubject but not with Subject, why is that? – Lajos Bela Jul 31 '21 at 13:43
  • Hey Jeffry, it not working means that it doesnt display the value in the component view, so if I say ..subscribe(returnedData) => {this.componentVariable = returnedData.name} Its not displaying it in the view, you can console log it, but cant display it in the view, thats why its useless – Lajos Bela Jul 31 '21 at 13:45

0 Answers0