Ehouarn Ehouarn - 1 month ago 10
TypeScript Question

How to implement a loading spinner on content change with the ASP.NET Core Angular SPA template?

I just setup a toy project based on the Angular template for ASP.NET Core 2.0 in order to create a SPA for testing purposes:

I know that the server pre-rendering process is already making things a lot faster for a SPA but just in case of latency.

But still how to achieve this? Can it actually be fully automatized (like applicable to all the views when they are coded on the client side (!*.cshtml)) ?


Answer Source

If you want a spinner on route changes, you can set a flag as part of the router events:

checkRouterEvent(routerEvent: Event): void {
    if (routerEvent instanceof NavigationStart) {
        this.loading = true;

    if (routerEvent instanceof NavigationEnd ||
        routerEvent instanceof NavigationCancel ||
        routerEvent instanceof NavigationError) {
        this.loading = false;

Then turn on/off a spinner based on that flag.

In the HTML:

<span class="glyphicon glyphicon-refresh glyphicon-spin spinner" *ngIf="loading"></span>

I have a working example set up here: (In the APM-Final folder).