【发布时间】:2017-05-23 15:04:27
【问题描述】:
让我们看一下这个例子。我正在尝试返回一个可观察的值 从订阅,但不知何故我得到空值。 这是我的问题的划痕:
this.userService.getAll().subscribe((userCollection) => {
userCollection.data.forEach((user) => {
let data = {
id: user.id
domainName: this.userService.getDomain(user.id).subscribe(
(domain) => {
console.log(domain.name); // I can see this in console
return Observable.of(domain.name);
}
)
};
this.array.push(data);
});
});
模板:<div *ngFor="let values of array|async">
{{ values.id }}
{{ values.domainName }} //empty
</div>
有人可以帮忙吗?我做得对吗?
【问题讨论】:
标签: angular observable angular-promise angular2-services