【发布时间】:2018-10-04 18:43:16
【问题描述】:
所以我的 Typescript 类中有两个变量:
private myServiceSubscription: Subscription;
myVar: myDto[] = [];
在 ctor 中:
this.myServiceSubscription = this.deliveryPointService
.getPostalAddresses()
.subscribe(result => console.log(result));
我可以在控制台日志中看到服务返回的预期结果(包含两项的列表) 但是,如果我改用另一个订阅:
.subscribe(result => this.myVar);
和(在订阅之外): console.log(this.myVar[0]);
然后我注意到 this.myVar 是未定义的。
为什么 console.log(result) 显示正确的结果,而 this.myVar 却没有?
这是角度 4。
【问题讨论】: