【发布时间】:2016-11-11 13:01:59
【问题描述】:
我有以下代码:
this.itemsService.getItems()
.subscribe(i => this.items = i);
但是,用户可以选择一种类型的项目,所以我有一个事件发射器:
this.typeofitems.selectedType.subscribe(type => this.type = type);
它运行良好。
现在我想用filter function 过滤this.items 的项目列表。问题是,我不知道项目的加载何时完成,尽管我在订阅中添加了日志:
this.itemsService.getItems()
.subscribe(i => {this.items = i; console.log("completed");});
它表明我已经完成了。所以我尝试了:
this.itemsService.getItems()
.subscribe(i => {
this.items = i;
this.typeofitems.selectedType.subscribe(type => {
this.type = type;
this.filterByType();
});
});
filterByType() {
this.itemsfilteredByType = this.items.filter(i => i.type === this.type)
}
但它不起作用。所以我想我不能在下标内订阅。 我怎样才能实现它?
【问题讨论】:
标签: angular typescript rxjs rxjs5