我正在研究angular 13版本。我有三个组成部分。其中两个有市中心的名单。选择这些下拉列表时,我将把所选值保存到NgRx存储。在我的第三个组件中,我必须从存储中订阅选定的dop-down值。根据上面的存储值,我需要将这些值作为参数传递给我支持的API
这是我的ngOnInit代码
ngOnInit(): void {
this.co1figFacade.getSeleConSet().subscribe((data: string) => {
if (data.length > 0) {
this.cuConfSet = data;
}
});
this.coFacade.getCurrentCoType().subscribe((data: string) => {
if (data.length > 0) {
this.conType = data;
}
});
if(this.conType .length>0 && this.cuConfSet.length>0){
this.getData(this.cuConfSet,this.conType );
}
}
我如何解决这个问题
我正在尝试做以下步骤
1.订阅两个方法(getSeleConSet和getCurrentCoType(这两个方法返回一个字符串值。
2如果两个响应不为null。我需要将这两个响应作为参数传递给getData方法
您需要使用combineLatest
来连接两个可观察器,然后使用tap
来检查并处理返回的数据。
ombineLatest(
this.co1figFacade.getSeleConSet(),
this.coFacade.getCurrentCoType()
)
.tap(([v1, v2]) => {
if(v1 && v2) {
this.getData(this.cuConfSet,this.conType );
}
}).subscribe();