首页 > 移动平台 > 详细

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

时间:2019-10-05 00:22:45      阅读:126      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!