导航结束后,发生使用路由器事件的DOM更改。是否有替代解决方案或解决方案?

时间:2019-02-15 12:59:49

标签: angular routing

导航开始时将显示一个隐藏的HTML元素,其中显示“正在加载...”,导航结束/取消/错误时将隐藏该HTML元素。但是在导航时,更改的确会随着元素样式的发生而发生,但仅在导航结束后才会显示(这是我在隐藏元素之前设置了第二个超时后捕获的)。作为临时解决方案,我正在使用一条指令,该指令在“ mousedown”上显示元素,但是存在问题。任何建议都值得赞赏,即使是临时修复。

通过https://www.amadousall.com/angular-routing-how-to-display-a-loading-indicator-when-navigating-between-routes/

strace: Exit of unknown pid 14 ignored

HTML:

this._router.events.subscribe((event: Event) => {
  if (event instanceof RouteConfigLoadStart || event instanceof NavigationStart) {
    // could not work with style change here as DOM changes are stopping until navigation is complete
    this.loadingDisplay = true;
  } else if (event instanceof NavigationEnd || event instanceof NavigationError || event instanceof NavigationCancel) {
    setTimeout(() => {
      this.loadingDisplay = false;
    }, 1000);

  }
});

元素的display和“ loadingDisplay”的值确实发生了变化,但是没有发生变化。

0 个答案:

没有答案