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来获取数据。你可以根据自己的需求使用适当的服务来获取数据。

相关内容

热门资讯

记者获悉!hhpoker透视脚... 记者获悉!hhpoker透视脚本视频(透视)爱玩联盟辅助软件(都是有辅助app)-哔哩哔哩一、爱玩联...
日前!wejoker辅助软件视... 日前!wejoker辅助软件视频(透视)微乐贵阳麻将辅助(一直有辅助下载)-哔哩哔哩1、打开软件启动...
据监测!we-poker靠谱吗... 据监测!we-poker靠谱吗(透视)威信茶馆大贰破解(本来是有辅助app)-哔哩哔哩1、每一步都需...
做出回应!hhpoker哪个俱... 做出回应!hhpoker哪个俱乐部靠谱(透视)捉住捣蛋鸡作必弊(真是存在有辅助插件)-哔哩哔哩1、捉...
透视游戏!德州透视竞技联盟(透... 透视游戏!德州透视竞技联盟(透视)哈灵脚本辅助(本来真的是有辅助平台)-哔哩哔哩哈灵脚本辅助破解侠是...
现有说明如下!aapoker真... 您好,福建天天开心辅助器是真的码这款游戏可以开挂的,确实是有挂的,需要了解加去威信【13670430...
来临!wepokerplus透... 来临!wepokerplus透视脚本免费(透视)广东雀神祈福辅助器(本来是真的辅助安装)-哔哩哔哩暗...
透视有挂!hhpoker是真的... 透视有挂!hhpoker是真的还是假的(透视)广西老友玩有破解(一直真的有辅助平台)-哔哩哔哩1、上...
推出新举措!we poker游... 推出新举措!we poker游戏下(透视)微信小程序开心泉州辅助器(好像是有辅助工具)-哔哩哔哩1、...
透视实锤!hhpoker到底可... 透视实锤!hhpoker到底可以作必弊吗(透视)天天卡五星辅助(真是有辅助修改器)-哔哩哔哩;1、用...