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

相关内容

热门资讯

透视最新"哈糖大菠萝... 透视最新"哈糖大菠萝怎么开挂"详细辅助透明教程(免费透视脚本软件)1、点击下载安装,微扑克wpk插件...
透视讲解"wepok... 1、透视讲解"wepokerplus透视脚本免费"详细辅助安装教程(透视方法辅助)。2、wepoke...
透视工具"德州私人局... 透视工具"德州私人局脚本"详细辅助靠谱教程(插件功能辅助器方法);原来确实真的有挂(需添加指定薇13...
透视软件"德州机器人... 透视软件"德州机器人代打脚本"详细辅助AI教程(辅助器安装包定制技巧)准备好在德州机器人代打脚本 i...
透视新版"wepok... 透视新版"wepoker免费透视脚本"详细辅助大神讲解(游戏下载透视),支持语音通讯、好友开房及战队...
透视肯定"hhpok... 透视肯定"hhpoker免费透视脚本"详细辅助力荐教程(私人局俱乐部辅助技巧);科技安装教程;136...
透视私人局"wepo... 透视私人局"wepoker私人局俱乐部辅助"详细辅助教你攻略(透视脚本免费软件);小薇(透视辅助)致...
透视讲解"hhpok... 透视讲解"hhpoker软件靠谱吗"详细辅助大神讲解(淘宝买透视有用技巧)准备好在hhpoker软件...
透视科技"德普之星透... 透视科技"德普之星透视免费"详细辅助攻略教程(代打辅助教程);建议优先通过德普之星透视免费透明挂内置...
透视有挂"poker... 透视有挂"pokerworld辅助器"详细辅助分享教程(透视app下载神器);最新版2024是一款经...