Angular页面在所有数据完成之前加载。
创始人
2024-10-30 11:30:37
0

在Angular中,可以使用*ngIf指令结合loading标志来控制页面加载的时机。下面是一个示例代码:

component.ts:

import { Component, OnInit } from '@angular/core';
import { DataService } from 'path/to/data.service';

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css']
})
export class MyComponentComponent implements OnInit {
  data: any; // 存储从服务获取的数据
  loading: boolean = true; // 控制页面加载的标志

  constructor(private dataService: DataService) { }

  ngOnInit() {
    this.getData();
  }

  getData() {
    this.dataService.getData().subscribe(response => {
      this.data = response;
      this.loading = false; // 数据加载完成后,将loading标志设置为false
    });
  }
}

component.html:

Loading...
  • {{ item }}

在上面的示例中,loading变量初始值为true,所以页面一开始会显示"Loading..."。当数据加载完成后,loading变量会被设置为false,然后数据会显示在页面上。

请注意,上述示例中使用了DataService来获取数据。你可以根据自己的需求使用适当的服务来获取数据。

相关内容

热门资讯

透视辅助!wepoker辅助器... 透视辅助!wepoker辅助器下载,微信微乐游戏有辅助吗,曝光透视(有挂方式)-哔哩哔哩1、许多玩家...
透视辅助!wepoker透视方... 透视辅助!wepoker透视方法,微乐自建房脚本使用安全吗,了解脚本(有挂总结)-哔哩哔哩wepok...
脚本透视!hhpkoer辅助挂... 脚本透视!hhpkoer辅助挂是真的吗,hhpoker有后台操作吗(透视)确实真的是有挂(哔哩哔哩)...
据玩家消息!wepoker软件... 据玩家消息!wepoker软件安装包,微乐自建房辅助神器怎么安装,教你脚本(确实有挂)-哔哩哔哩1、...
透视攻略!德州局HHpoker... 透视攻略!德州局HHpoker透视脚本,微乐小程序辅助开发透视,有挂脚本(有挂技巧)-哔哩哔哩1、德...
透视开挂!hhpoker辅助,... 透视开挂!hhpoker辅助,hh poker辅助器先试用(透视)其实是真的软件(哔哩哔哩)暗藏猫腻...
透视分享!aapoker辅助器... 透视分享!aapoker辅助器是真的吗,aapoker怎么开辅助器(透视)好像存在有挂(哔哩哔哩)1...
值得注意的是!线上德州的辅助器... 值得注意的是!线上德州的辅助器是什么,广西微乐小程序微信辅助器免费,详情透视(有挂方针)-哔哩哔哩1...
透视了解!aapoker如何设... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家在这款游戏中打...
透视攻略!hhpoker软件安... 透视攻略!hhpoker软件安装包,微乐小游戏万能修改器,详情透视(有挂秘诀)-哔哩哔哩亲,关键说明...