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

相关内容

热门资讯

透视解迷"德普之星a... 透视解迷"德普之星app安卓版破解版"本来真的有辅助攻略(哔哩哔哩)1)德普之星app安卓版破解版辅...
透视透视"hhpok... 透视透视"hhpoker有没有作必弊挂"确实存在有辅助教程(哔哩哔哩)1、让任何用户在无需hhpok...
透视解密"hhpok... 透视解密"hhpoker软件可以玩吗"好像存在有辅助挂(哔哩哔哩);1、hhpoker软件可以玩吗辅...
透视有挂"wepok... 透视有挂"wepoker有用吗"其实有辅助攻略(哔哩哔哩)1、下载好wepoker有用吗脚本下载之后...
透视关于"wepok... 透视关于"wepoker有透视功能吗"竟然是有辅助插件(哔哩哔哩)1、wepoker有透视功能吗模拟...
透视详情"we po... 透视详情"we poker游戏下"真是存在有辅助挂(哔哩哔哩)1、we poker游戏下模拟器是什么...
透视教你"wepok... 透视教你"wepoker免费脚本咨询"一贯是真的辅助脚本(哔哩哔哩)1、很好的工具软件,可以解锁游戏...
透视揭露"aapok... 透视揭露"aapoker ai插件"竟然真的是有辅助器(哔哩哔哩)1、操作简单,无需aapoker ...
透视关于"aapok... 透视关于"aapoker透视怎么用"其实真的是有辅助神器(哔哩哔哩)1、aapoker透视怎么用免费...
透视了解"德普之星的... 透视了解"德普之星的辅助工具介绍"一直存在有辅助软件(哔哩哔哩)暗藏猫腻,小编详细说明德普之星的辅助...