Sequential Execution of Function Inside NgOnInit [Angular]

  angular, javascript

I have two functions inside ngOnInit.

ngOnInit(): void {


I want to run the first function first and use the value of first in order to execute second.

public getUserInfo() {
    return this.userFeedService.getShowdaUserInfo().subscribe(
      (response: any) => {
        this.userId =;

  public getUserFeed() {
    return this.userFeedService.getShowdaUserFeed(this.params, this.userId).subscribe(
      (response: any) => { =;

But it seems that they are running parallelly. I need to retrieve userId from first function in order to get the user feed from the second. The userId is required for a get request in the second function. What should I do?

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.