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

问题描述 投票:0回答:1

我从服务器获取数据,将其传递到一个变量,然后再次转到它以将其添加到url中,但它始终提供它-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);

谢谢

angular6
1个回答
0
投票

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

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; 
});
© www.soinside.com 2019 - 2024. All rights reserved.