angular6 页面加载数据时的loading提示


使用npm安装ngx-loading模块

npm install --save ngx-loading

 

在app.module.ts中导入模块

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgxLoadingModule } from 'ngx-loading';

@NgModule({
  ...
  imports: [
    ...
      NgxLoadingModule ,
 ... ], ... }) export class AppModule { }

 

在对应的component.ts文件中增加loading属性

export class *Component implements OnInit {
  loading = false;
  ...
  get*Data(): void {
    this.loading = true;
    this.*Service.getData(url).subscribe(res => {
      ...
      this.loading = false;
      ...
    }, error => {
      ...
      this.loading = false;
      ...
    });
  }
}

 

最后,在html文件中加入下列代码即可:

<ngx-loading [show]="loading" [config]="{ backdropBorderRadius: '14px' }"></ngx-loading>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM