【发布时间】:2019-10-31 03:35:36
【问题描述】:
我有一个 subscription 来存储并基于来自商店的值,调用服务,我 subscribe 进一步。
嵌套订阅会导致性能问题吗?虽然onDestroy subscription 被销毁了。
ngOnInit() {
this.currentYear = (new Date).getFullYear();
this.statesubscription = this.contentServerStore
.pipe(select(getContentServerState))
.subscribe(val => {
if (!this.checkValuesService.isNullOrUndefined(val) &&
val.region.toUpperCase() == Constants.region.us
) {
let contentRequest = new ContentRequest();
this.regionService.getRegion(contentRequest).subscribe(region => {
if (!this.checkValuesService.isNullOrUndefined(region)) {
this.regionContent = <string>this.domSanitizer
.bypassSecurityTrustHtml(region[Constants.regionKey]);
}
});
}
});
}
【问题讨论】:
-
您不会注意到上面的代码并出现问题,但尝试在管道中使用
flatMap运算符以获得更好的性能
标签: angular subscription