码迷,mamicode.com
首页 > 移动开发 > 详细

[Angular] How to show global loading spinner for application between page navigation

时间:2019-10-05 00:28:03      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:glob   div   export   error   pst   route   eve   init   end   

app.component.ts:

import { Component, OnInit } from "@angular/core";
import { select, Store } from "@ngrx/store";
import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import {
  NavigationCancel,
  NavigationEnd,
  NavigationError,
  NavigationStart,
  Router
} from "@angular/router";
import { AppState } from "./reducers/index";
import { isLoggedIn, isLoggedOut } from "./auth/auth.selectors";
import { AuthActions } from "./auth/action-types";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit {
  loading = true;

  constructor(private store: Store<AppState>, private router: Router) {}

  ngOnInit() {
    ...this.router.events.subscribe(event => {
      switch (true) {
        case event instanceof NavigationStart: {
          this.loading = true;
          break;
        }

        case event instanceof NavigationEnd:
        case event instanceof NavigationCancel:
        case event instanceof NavigationError: {
          this.loading = false;
          break;
        }
        default: {
          break;
        }
      }
    });
  }

}
<div class="spinner-container" *ngIf="loading">
    <mat-spinner></mat-spinner>
  </div>

 

[Angular] How to show global loading spinner for application between page navigation

标签:glob   div   export   error   pst   route   eve   init   end   

原文地址:https://www.cnblogs.com/Answer1215/p/11623738.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!