Angular 隐藏加载程序之前的图像加载

Angular 隐藏加载程序之前的图像加载,angular,mdbootstrap,Angular,Mdbootstrap,我的角度应用程序有问题。我从服务器获取数据,包括图像,并希望在所有加载后隐藏加载程序动画。加载程序隐藏后,即时图像也会加载 下面是隐藏加载程序的代码: ngAfterViewInit(): void { this.preloader.stop(); } 数据由具有解析器的服务获取 有人能帮我吗 谢谢 我想你能做的是: 您应该在Angular中为后端API调用下标 this.yourAPICallService.subscribe((res)=>{ //You sho

我的角度应用程序有问题。我从服务器获取数据,包括图像,并希望在所有加载后隐藏加载程序动画。加载程序隐藏后,即时图像也会加载

下面是隐藏加载程序的代码:

ngAfterViewInit(): void {
   this.preloader.stop();
}
数据由具有解析器的服务获取

有人能帮我吗


谢谢

我想你能做的是:

您应该在Angular中为后端API调用下标

  this.yourAPICallService.subscribe((res)=>{
      //You should get all data from the server here
    },
    (error: any) => {
      //catch any error
      console.info(error);
    },
    ()=>{
      //codes should be executed after the completion of the API call
      this.preloader.stop();
    }
 );

当您使用服务从服务器获取数据时,很可能您的服务方法返回的是可观察的。您需要订阅可观察到的内容

subscribe是实际执行可观察的的函数。它需要三个回调参数:

订阅(成功、失败、完成)

例如:

this.service.getDataFromServer().subscribe(
        function(response) { // executes when success
            console.log("Success" + response);
        }, 
        function(error) { // executed when failure
            console.log("Error" + error);
        }, 
        function() { // executes when completed
            console.log("Completed");
            this.preloader.stop();
        } 
    );

谢谢,但这并不能修复错误。这与在路由上使用解析器获取数据是一样的。现在,若渲染组件,所有信息都会显示,但在渲染后很短时间内图像会弹出


最好的问候

请您提供HTML代码,以便更好地理解您的问题