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、打开软件启动之后找到中间准星的标志...
玩家必看分享!AAPoKer辅... 玩家必看分享!AAPoKer辅助挂多功能透视工具,都是真的是有挂(了解有挂)AAPoKer透视方法中...
一分钟秒懂!AAPoKer辅助... 一分钟秒懂!AAPoKer辅助挂多功能透视工具,一直真的有挂(有挂解惑)1、在AAPoKer插件功能...
发现一款!红龙poker辅助挂... 发现一款!红龙poker辅助挂多功能透视工具,确实真的是有挂(有人有挂)1、红龙poker脚本辅助下...
分享一款!智星菠萝德州辅助挂多... 分享一款!智星菠萝德州辅助挂多功能透视工具,切实存在有挂(揭秘有挂)1、在智星菠萝德州插件功能辅助器...
科技通报!aapoker辅助挂... 科技通报!aapoker辅助挂多功能透视工具,切实是真的有挂(有挂规律)1、完成aapoker辅助器...
带你了解!aapoker辅助挂... 带你了解!aapoker辅助挂多功能透视工具,总是是真的有挂(有挂透视)小薇(辅助器软件下载)致您一...
盘点一款!红龙poker辅助挂... 盘点一款!红龙poker辅助挂多功能透视工具,真是存在有挂(有挂技巧)1、任何红龙poker透视是真...
一起来探讨!wepoker辅助... 一起来探讨!wepoker辅助挂多功能透视工具,确实真的有挂(有挂秘诀)暗藏猫腻,小编详细说明wep...
实操分享!wpk辅助挂多功能透... 实操分享!wpk辅助挂多功能透视工具,总是是真的有挂(有挂解密)1、全新机制【wpkai辅助工具激活...