Make url dynamic depending on Observable answer [duplicate]

This question already has an answer here:

I have the following task. I have to make a URL dynamic. For this I need an ID first. I call this Id:


    export class MyClass {

        myUrl: string;
        myMethod () {
              this.myService.getApi (). subscirbe ((id) =>
                    {
                  myUrl = "http: //blbalal" + id + "balala";
        })
        console.log (myUrl)  // undefined
        return myUrl
        }

        }

The problem is, the url will be called bevor i get the id. Is there a way to wait for the Id before I can use myUrl?

I tried to solve the problem with Promise by

  

async getId () {
          const id = await MyService.getApi (). toPromise (). then (resp => resp as myObject); * /
        return id;
       }
but unsuccessful. It has cost me many hours. Other answers could not help me any further. What am I doing wrong here.

Source: New feed
Source Url Make url dynamic depending on Observable answer [duplicate]