首页 > 解决方案 > end void 方法后重定向

问题描述

刷新页面时遇到问题

我有一个运行以下代码的服务:

服务.ts

public goToCommit(value: boolean) {
    if (this.accountServ.isAutho() || this.person.getNb() % 48 === 0) {
        this.personService.savePerson(this.person).subscribe(() => {
          this.person= null;
        });
      } else {
        throw new Error('Account not authorized to goToCommit');
      }
  }

(这个处理比较长,其他地方也用这个方法)

在我的组件中,我有这个:

组件.ts

this.service.goToCommit(value);
this.router.navigate (['/persons']);

问题是我/persons在处理结束之前被重定向到。

我如何等待goToCommit方法完成并在之后重定向?

谢谢

标签: angularredirectnavigationcomponentssubscribe

解决方案


推荐阅读