title: passing data into the constructor gives me undefined
body: <p>I am retrieving data from the server in the <code>constructor</code>, and passing those date into a variable, but when I tried to use it in the outer scope, it keep giving <code>undefined</code>. I need to get the <code>userID</code> from the profile data, how can I solve this?</p>
  <pre><code>constructor(
    public service: OrderService,
    private dialog: MatDialog,
    private toastr: ToastrService,
    public UserService: UserService,
  ) {
    // get user details, to get user Order
    this.UserService.getUserProfile().subscribe(
      res =&gt; {
        this.userDetails = res as[],
        console.log(this.userDetails.id)
        this.userId = this.userDetails.id;
        console.log(this.userId)
      },
      err =&gt; {
        console.log(err.err);
      }
    );
  }
  
  testPrintUserID() {
    console.log(this.userId)
  }
  </code></pre>