1

When I change the page ,I home the web app shows the progress,when new page loaded finish,the pregress disappear,it looks like the picture below. enter image description here

I have a way to realize the goal.
Create a service,then add providers in every page component.Secondly,implements OnDestroy and OnAfterContentChecked.In ngOnDestroy,inform the service start the progress,in ngOnAfterContentChecked,inform the service stop the progress.

But that's too troublesome.I think there has a better way to realize the target.Who can help me? Or recommand me a plugin.

2
  • A fully automatic loading bar with zero configuration for Angular app : github.com/aitboudad/ngx-loading-bar Commented Jul 31, 2018 at 3:52
  • 3
    You can subscribe to router events at the root of your application. Every time a new NavigationStart event is fired show progress bar and then when the NavigationEnd event is fired hide progress bar. Commented Jul 31, 2018 at 3:53

1 Answer 1

1
    constructor(private router: Router, private ngZone: NgZone,
private renderer: Renderer,) {
        router.events.subscribe((event: RouterEvent) => {
          this._navigationInterceptor(event);
        });
      }
     private _navigationInterceptor(event: RouterEvent): void {
        if (event instanceof NavigationStart) {
      // bypass change detection
      this.ngZone.runOutsideAngular(() => {

      });
    }
}
  if (event instanceof NavigationEnd) {

    }

    if (event instanceof NavigationCancel) {

    }
    if (event instanceof NavigationError) {

    }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.