控制台日志未定义

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了控制台日志未定义相关的知识,希望对你有一定的参考价值。

控制台日志在这里未定义

      this.http.get(this.rootURL + "/Report/"+id)
      .toPromise().then(res => this.report = res as Report);
      console.log(this.report);
  }  

这里控制台记录数据

      this.http.get(this.rootURL + "/Report/"+id)
      .toPromise().then(res => console.log(res));
      console.log(this.report);
  }  

如何将结果分配给Result Object

答案

thenpromise中记录您的数据:

this.http.get(this.rootURL + "/Report/"+id)
  .toPromise()
  .then(res => {
    // Promise gets fulfilled and its response can be assigned
    this.report = res as Report;
    console.log(this.report);

    // Perform other actions
    // ...
  })
  .catch(reason => {
    // Something went wrong, your promise gets rejected
    console.log(reason);
  });
另一答案

你在等待吗?

你应该做这样的事情: