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透视脚本免费使用视频(透视)约局吧辅助器下载(确实有辅助神器)-哔哩哔哩亲,...
透视存在!德普之星辅助器怎么用... 透视存在!德普之星辅助器怎么用(透视)网易游戏辅助工具(一直真的是有辅助平台)-哔哩哔哩网易游戏辅助...
透视神器!wejoker辅助脚... 透视神器!wejoker辅助脚本(透视)蜀山四川小程序破解版下载(总是存在有辅助辅助器)-哔哩哔哩1...
此事引发网友热议!wejoke... 此事引发网友热议!wejoker辅助软件(透视)苹果手机闲逸辅助器(确实有辅助软件)-哔哩哔哩1、玩...
一直以来!hhpoker真能买... 一直以来!hhpoker真能买到挂吗(透视)微友助手破解版(其实存在有辅助平台)-哔哩哔哩1、下载好...
近日!约局吧开挂神器是真的吗(... 近日!约局吧开挂神器是真的吗(透视)四川皮皮辅助(切实真的是有辅助修改器)-哔哩哔哩四川皮皮辅助能透...
昨日!wepoker辅助器怎么... 昨日!wepoker辅助器怎么弄(透视)胡易辅助软件(确实是真的辅助工具)-哔哩哔哩胡易辅助软件是不...
现有关情况通报如下!wepok... 现有关情况通报如下!wepoker破解工具(透视)边锋老友威海荣成辅助(好像真的是有辅助辅助器)-哔...
透视有挂!如何判断wpk辅助软... 透视有挂!如何判断wpk辅助软件的真假(透视)科乐填坑辅助器(一贯真的有辅助辅助器)-哔哩哔哩科乐填...
透视中牌率!wepoker怎么... 透视中牌率!wepoker怎么设置房间(透视)斗棋崇阳麻将辅助脚本(其实存在有辅助工具)-哔哩哔哩1...