0

I use the angular2.0 release version. When I load a lazy router,If the router has a lot of code,It's almost 1MB,The browser needs to wait for some time,It's unfriendly,so I want create a loading animation. Whether angular2 provided the event or directive?

sorry about my english is bad.

1 Answer 1

1

My suggestion is this:

  • Set up a service that exposes a public flag through a BehaviorSubject/Observable. Let's call it isLoading$

  • Use CanActivate to detect when lazy-loading starts: emit true on isLoading$

  • When the module has loaded, emit false on isLoading$ from the module's entry component's onInit().

  • Create a spinner or similar to indicate loading: *ngIf="isLoading$ | async"

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

1 Comment

Thanks, I found a way this.router.events.subscribe((event)=>{ var isStart = event instanceof NavigationStart; var isEnd = event instanceof NavigationEnd || event instanceof NavigationError; if(isStart)this.appProvider.PageIsLoading = true; if(isEnd)this.appProvider.PageIsLoading = false; });

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.