【问题标题】:How to stop loading spinner in angular 11如何停止以角度 11 加载微调器
【发布时间】:2022-02-14 19:55:14
【问题描述】:

我在我的应用程序中添加了加载微调器。我想在显示 PDF 时停止它。我添加了代码来停止加载,但它不可行。如何解决这个问题。

pdf.component.html

<section>
    <div style='position: relative; height: 100%;'>
        <pdf-viewer style="width: 20px" [src]="pdfsrc+data[0].pdf_name" [render-text]="true" style="display: block;" [rotation]="0"
            [original-size]="false" [show-all]="true" [fit-to-page]="true" [zoom]="0" [zoom-scale]="'page-width'" [stick-to-page]="false"
            [render-text]="true" [external-link-target]="'blank'" [autoresize]="true" [show-borders]="false"></pdf-viewer>
    </div>
</section>
<ngx-spinner bdColor="rgba(51, 51, 51, 0.8)" size="default" type="ball-spin-clockwise">
    <p style="color: rgb(33, 221, 118)">Be Patince PDF is loaded. </p>
</ngx-spinner>

pdf.component.ts

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ApiService } from '../api.service';
import { NgxSpinnerService } from "ngx-spinner";

@Component({
  selector: 'app-pdf',
  templateUrl: './pdf.component.html',
  styleUrls: ['./pdf.component.css']
})
export class PdfComponent implements OnInit {

  constructor(private aroute: Router, private formBuilder: FormBuilder, private SpinnerService: NgxSpinnerService, private api: ApiService, private activeRoute: ActivatedRoute, private route: Router) {

  }
  data: any;
  //totalPages:any;
  submitted = false;
  ngOnInit(): void {
    this.SpinnerService.show();
    window.scrollTo(0, 0);
    this.api.tbl_report_pdf_data_one(this.activeRoute.snapshot.params.pdfid).subscribe((res) => {
      this.data = res;
  this.SpinnerService.hide();
    })
page: number = 1;
  isLoaded: boolean = false;
  pdfsrc: any = "assets/uploads/";

【问题讨论】:

    标签: angular spinner loading loaded ngx-spinner


    【解决方案1】:

    这应该很简单,只需在你的 HTML 中使用 isLoaded:

    <ngx-spinner *ngIf="!isLoaded" bdColor="rgba(51, 51, 51, 0.8)" size="default" type="ball-spin-clockwise">
        <p style="color: rgb(33, 221, 118)">Be Patince PDF is loaded. </p>
    </ngx-spinner>
    

    this.api.tbl_report_pdf_data_one(this.activeRoute.snapshot.params.pdfid).subscribe((res) => {
      this.data = res;
      this.isLoaded = true;
    })
    

    【讨论】:

    • 抱歉,您的代码不可用。我试过你的代码。实际上我已经导入了 NgxSpinnerService 并使用 (this.SpinnerService.show(); ) 来显示加载器。也添加了(this.SpinnerService.hide ();)但这不可行,而且我担心它无法正常工作。
    • 这里的url我更喜欢添加加载器c-sharpcorner.com/article/…
    • 所以这个 NgxSpinner 很奇怪,但是没关系……它出现了吗?和剂量 subscribe() 工作?请在 this.SpinnerService.hide() 之前添加一个 console.log();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 2019-07-11
    • 2018-12-02
    • 2018-05-01
    相关资源
    最近更新 更多