Angular 角度/类型脚本:在订阅中编写代码
我正在使用Angular(4),需要帮助处理异步数据: 下面可以看到connect()方法。第一个命令订阅我的服务的一个可观察对象。此订阅中也需要包含以下行。但我不知道怎么做。该方法应将getSortedData()方法的结果作为可观察结果返回 我的项目组件Angular 角度/类型脚本:在订阅中编写代码,angular,typescript,Angular,Typescript,我正在使用Angular(4),需要帮助处理异步数据: 下面可以看到connect()方法。第一个命令订阅我的服务的一个可观察对象。此订阅中也需要包含以下行。但我不知道怎么做。该方法应将getSortedData()方法的结果作为可观察结果返回 我的项目组件 //... items: Item[]; //... connect(): Observable<Item[]> { this.myItemService.getItem()
//...
items: Item[];
//...
connect(): Observable<Item[]> {
this.myItemService.getItem().subscribe(response => {
this.items = response;
});
const displayDataChanges = [
this.myItemService.getItem(),
this.sort.sortChange,
];
return Observable.merge(...displayDataChanges).map(() => {
return this.getSortedData(this.items);
});
}
//..
/。。。
项目:项目[];
//...
connect():可观察{
this.myItemService.getItem().subscribe(响应=>{
此项=响应;
});
const displayDataChanges=[
此.myItemService.getItem(),
this.sort.sortChange,
];
返回可观察的.merge(…displayDataChanges).map(()=>{
返回此.getSortedData(此.items);
});
}
//..
不要读取运算符内部的可变状态。当它们更改时,可观察对象将不知道,也不会再次运行代码
因此我删除了this.items
的用法,并将sort
参数传递给getSortedData()
connect():可观察{
const displayDataChanges=[
此.myItemService.getItem(),
this.sort.sortChange,
];
返回可观察的.CombineTest(…displayDataChanges).map([items,sort])=>{
返回此.getSortedData(项目,排序);
});
}
很酷,谢谢,但我再也没有收到我的数据了。“可观测类型”上也不存在combineDate。你知道吗?我的排序是'@ViewChild(MatSort)排序:MatSort;'所以我想在我的getSortedData方法direct中使用this.sort。有可能吗?哪种组合?!对不起,我的意思是在项目中导入一次“rxjs/Observable/add/combineLatest”