【发布时间】:2019-12-07 21:30:45
【问题描述】:
我有两个服务,我需要从每个服务中获取一个 observable。我在互联网上搜索并找到了一个解决方案,在这里:Is it good way to call subscribe inside subscribe? 但这对我不起作用。 这两个 observable 单独调用时效果很好。
export class EditVarianteComponent implements OnInit {
public currentVariante: Variante;
public url: string;
public value$: any;
constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
private varService: VarianteService,
private famService: FamillesService
) {}
ngOnInit() {
this.url = atob(this.activatedRoute.snapshot.params.id);
//Here, I get the resource, and I want the result of this resource to be the parameter of my second observable
this.varService.getResource(this.url)
.pipe(
flatMap((res1) => this.famService.getFamilleById(res1.id_famille))
)
.subscribe((res3) => {
console.log(res3);
});
}
【问题讨论】:
-
控制台有错误吗?
-
是的,res1.id_famille 未定义。
-
如果您控制台日志 res1 是否返回任何内容?
-
“res1.id_famille 未定义”或“无法读取未定义的属性 'id_famille'”?
getResource的作用如何?
标签: angular