简体   繁体   English

角度-导航到可观察结果的路线

[英]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.

相关问题 导航到Angular 2中的当前路线? - Navigating to the current route in Angular 2? 如何在Angular路线防护中使用Observable? - How to use an Observable in Angular route guard? 在没有导航的情况下从Component添加参数到Angular 2 Route - Add Parameter to Angular 2 Route from Component without Navigating 在 Angular 8 路由父路由与其他父路由导航时保持不变 - In Angular 8 Router parent route remains the same when navigating to the route with other parent Angular2路线守卫返回Observable <bool> ,如何处理错误 - Angular2 route guard returning Observable<bool>, how to handle errors 如何返回 Observable<boolean> 在 Angular 6 中的受保护路线上的 canActivate - How to return Observable<boolean> in canActivate on a guarded route in Angular 6 angular2 / rxjs / redux重新实现-路由变化混乱,可观察 - angular2/rxjs/redux reimplementation - route change messing with observable 反应:私人路线不导航 - React: private route not navigating 使用来自对话框的输入订阅可观察的异步地图结果,使用地图的结果到路由 - Subscribe to observable, async map result with input from dialog, use result from map to route 在Angular中,如何返回带有诺言的结果和错误的Observable - In Angular, how to return an Observable with result and errors from a promise
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM