Angular 组件中的 6 个服务器输出 (component.js)

Angular 6 server output in component (component.js)

我从服务器获取数据并将其分配给一个变量。但是当我用它来添加到另一个变量时,它总是给出 - undefined。当此变量显示在 app.html 中时,一切都会正确显示

{{nodesID}} // 好的结果 = 15

component.ts
   nodesID: any; //tried - number and string
   public url = 'http://localhost:8080/nodesID'; // undefined, should be 15

    this.serviceNodes.getCleitnId(Tokenstorageservice.myUsername())
      .subscribe(result => this.nodesID = result);

从服务器获取数据后,将值赋给变量。

nodesID: any; //tried - number and string
public url = ''; // don't assign the nodesID at this point 

this.serviceNodes.getCleitnId(Tokenstorageservice.myUsername())
  .subscribe(result => {
       this.nodesID = result
       this.url = 'http://localhost:8080' + '/' + this.nodesID; 
});