Angular 如何在角度应用程序中包含加载微调器?

Angular 如何在角度应用程序中包含加载微调器?,angular,typescript,progress-bar,angular-material,Angular,Typescript,Progress Bar,Angular Material,我正在尝试将微调器添加到我的应用程序中,但微调器没有出现 控制台或终端中没有出现错误,但微调器没有出现 loader.service.ts app.component.html 我认为你打错电话给你的加载器服务 您的加载程序代码逻辑是 this.loaderService.display(true); //http call ends this.loaderService.display(false); 在custom.component.ts中编写,您的HTML代码在app.componen

我正在尝试将微调器添加到我的应用程序中,但微调器没有出现

控制台或终端中没有出现错误,但微调器没有出现

loader.service.ts app.component.html
我认为你打错电话给你的加载器服务

您的加载程序代码逻辑是

this.loaderService.display(true);
//http call ends
this.loaderService.display(false);
在custom.component.ts中编写,您的HTML代码在app.component.HTML中编写

尝试在custom.component.HTML中使用相同的HTML代码,或尝试添加

this.loaderService.display(true);
//http call ends
this.loaderService.display(false);

在app.component.ts中使用此逻辑,或者您可以在app.component.html中打印除div之外的showLoader值,如{{showLoader}

我认为您调用加载程序服务的方式错误

您的加载程序代码逻辑是

this.loaderService.display(true);
//http call ends
this.loaderService.display(false);
在custom.component.ts中编写,您的HTML代码在app.component.HTML中编写

尝试在custom.component.HTML中使用相同的HTML代码,或尝试添加

this.loaderService.display(true);
//http call ends
this.loaderService.display(false);

app.component.ts中的这个逻辑,或者除了app.component.html中的div之外,还可以打印showLoader值,比如{{showLoader}

看起来像是范围问题。AppComponent的实例必须可用,subscribe函数才能使用该组件的变量。”这是指订阅功能的范围

export class AppComponent {
    //for the spinner
    showLoader: boolean;
    //LoaderService is for the spinner
    constructor(private loaderService: LoaderService) { }

    //for the spinner
     ngOnInit() {
         let self=this;

         this.loaderService.status.subscribe((val: boolean) => {
            self.showLoader = val;
         });
     }
}  

看起来像是范围问题。AppComponent的实例必须可用,subscribe函数才能使用该组件的变量。”这是指订阅功能的范围

export class AppComponent {
    //for the spinner
    showLoader: boolean;
    //LoaderService is for the spinner
    constructor(private loaderService: LoaderService) { }

    //for the spinner
     ngOnInit() {
         let self=this;

         this.loaderService.status.subscribe((val: boolean) => {
            self.showLoader = val;
         });
     }
}  

在Custom.component.ts类中,您一个接一个地调用下面的2条语句,而必须使用timeout

ngOnInit() {
  //http call starts
  this.loaderService.display(true);
  //http call ends
  setTimeout(() => {
            this.loaderService.display(false);
          },5000);

 }

通过执行此块,微调器将显示5秒


您也可以在Custom.component.ts类中使用ngx Spinner()

,您将一个接一个地调用下面的2条语句,而必须使用timeout

ngOnInit() {
  //http call starts
  this.loaderService.display(true);
  //http call ends
  setTimeout(() => {
            this.loaderService.display(false);
          },5000);

 }

通过执行此块,微调器将显示5秒


您也可以使用ngx Spinner()

我将div组件添加到custom.component.html中,但即使这样,它也没有出现。在打印showLoader值后,我一直遵循此链接的步骤是什么?您添加了正确的CSS吗?那么您是否尝试过打印showLoader值?它是什么?或者,尝试删除并仅添加类似加载的文本,然后检查它是否正常工作。我将其替换为
{{showLoader}
this。让我们来看看。我将div组件添加到custom.component.html中,但即使这样,它也没有出现。在打印showLoader值后,我一直遵循此链接的步骤是什么?您添加了正确的CSS吗?那么您是否尝试过打印showLoader值?它是什么?或者,尝试删除并只在该div中添加像LOADING这样的文本,并检查它是否正常工作。我将其替换为
{{showLoader}
this.让我们来看看。no brother问题出在custom.component.ts文件中的ngOnIt上,他在该文件中尝试了两次调用函数,第一次使用true值,第二次使用false值,因此默认情况下showLoader值将其设置为false。no brother问题出在custom.component.ts文件中的ngOnIt上,他在该文件中尝试了两次使用true值调用函数首先是值,然后是false值,因此默认情况下showLoader值将其设置为false。