Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript RxJS-将承诺链转换为可观察不工作_Typescript_Rxjs5 - Fatal编程技术网

Typescript RxJS-将承诺链转换为可观察不工作

Typescript RxJS-将承诺链转换为可观察不工作,typescript,rxjs5,Typescript,Rxjs5,我正在尝试转换承诺链接: this.tradeTypesLogicService.getList().$promise .then(this.filterTradeTypes) .then(this.setSelectedTradeType) 对于可观察到的rxjs: this.tradeTypesLogicService .getList() //returns observable now .pipe(mergeMap(this.filterTradeTyp

我正在尝试转换承诺链接:

this.tradeTypesLogicService.getList().$promise
    .then(this.filterTradeTypes)
    .then(this.setSelectedTradeType)
对于可观察到的rxjs:

this.tradeTypesLogicService
    .getList() //returns observable now
    .pipe(mergeMap(this.filterTradeTypes), map(this.setSelectedTradeType))
    .subscribe();



protected filterTradeTypes = (tradeTypes: Array<any>) => {
    this.tradeTypes = filter(tradeTypes, (trade) => {
        if (trade.id === this.mappedItem.tradeTypeId && !trade.isActive) {
            trade.label = trade.label + " (inactive)";
            return true;
        }
        return trade.isActive;
    });
    return this.tradeTypes;
}



public setSelectedTradeType = (tradeTypes): void => {
    this.selectedTradeTypeModel = tradeTypes.find(tt => tt.id === this.mappedItem.tradeTypeId);
}
this.tradeTypesLogicService
.getList()//立即返回可观察值
.pipe(合并映射(此.FilterTradeType)、映射(此.setSelectedTradeType))
.subscribe();
受保护的筛选器交易类型=(交易类型:数组)=>{
this.tradeTypes=过滤器(tradeTypes,(trade)=>{
if(trade.id==this.mappedItem.tradeTypeId&&!trade.isActive){
trade.label=trade.label+“(非活动)”;
返回true;
}
退货交易活跃;
});
返回此.tradeTypes;
}
公共设置SelectedTradeType=(交易类型):void=>{
this.selectedTradeTypeModel=tradeTypes.find(tt=>tt.id==this.mappedItem.tradeTypeId);
}

我需要将从
filterTradeTypes
返回的数组传递到
setSelectedTradeType
中,它只传递该数组中的一项

不完全是您所要求的,但是void方法应该传递给tap或subscribe@AluanHaddad我需要将从
filterTradeTypes
返回的数组传递到
setSelectedTradeType
中,它只传递该数组中的一项。没问题。这些帖子实际上并没有错,只是承诺和可观察的东西在嵌套承诺中是非常不同的抽象。所以,如果你有一个承诺,回报一个承诺,回报一个承诺,它只是回报一个承诺。所以实际上,有时
then
的翻译是
map
,有时是
mergeMap
。如果您正在应用一个函数,该函数在
中返回一个承诺,那么它将被合并映射,希望这是有意义的。。。我很累。另一个区别是mergeMap将它认为的高阶结构展平了一级。这些结构包括不可测性、可观测性和承诺