[英]Angular - Navigating to route with result of observable
I have an interesting issue that I can't seem to figure out. 我有一个似乎无法解决的有趣问题。
I am making a HTTP request which is returning an Observable. 我正在发出返回Observable的HTTP请求。 I am subscribing to the observable and using the value as a parameter to my route when calling router.navigate. 我正在订阅observable,并在调用router.navigate时将其值用作路由的参数。 The navigation works correctly but when I land on the new route I can't click anything, the page is completely locked. 导航正常,但是当我进入新路线时,我无法单击任何内容,页面已完全锁定。 As soon as I refresh the page everything works as expected. 刷新页面后,一切都会按预期进行。
Code snippet below for reference. 下面的代码段供参考。
createTemplate() {
this.templateService.create(this.templateModel)
.subscribe(template => {
this.router.navigate(['/admin/templates/builder', template.id]);
});
}
What this.templateService.create
method does? this.templateService.create
方法做什么? What kind of Observable returns? 什么样的可观察回报?
Maybe you have to close the subscription? 也许您必须关闭订阅?
createTemplate() {
this.templateService.create(this.templateModel)
.pipe(first())
.subscribe(template => {
this.router.navigate(['/admin/templates/builder', template.id]);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.