-2

How to do this without using setTimeout?

    let res;
    this.auth.getUser().subscribe((response) => {
        res = response;
    });
    setTimeout(() => {
        console.log(res);
    }, 1000)
Akash Kumar Verma
  • 3,185
  • 2
  • 16
  • 32
TaSvet
  • 382
  • 2
  • 10

2 Answers2

0

Try this.....

 import { Component, OnInit } from "@angular/core";

@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit {
  name = "Angular";
  ngOnInit() {

  }
  async getUser() {
    let res = await this.auth.getUser().toPromise();
    console.log(res);
  }
}
Murugan
  • 615
  • 5
  • 19
-1

Try the below code :

>    let res;
>     this.auth.getUser().subscribe((response) => {
>       res = response;
>       console.log('Your response:', res)
>     });
Kunvar Singh
  • 1,779
  • 2
  • 13
  • 21