ngOnInit() {
this.isLoading = true; //setting isLoading to true in order to show the loader
this.SomeService.load()
.subscribe(res => {
//do stuff with the data
//like iterate ,bind etc
this.isLoading = false; // setting the isLoading property back to false after doing req. stuff.
});
}
1 回答
转到要显示ActivityIndicator的页面并在顶部添加:
您必须在此页面的组件中创建名为isLoading的新属性,并将其初始化为false:
现在您拥有了这个属性,最后一步是在加载数据时将此属性设置为true以显示加载器 . 这将根据您的实现而有所不同 . 但是为了便于解释,我们可以考虑编写一些处理数据的服务,我们在组件中订阅它 . 我将利用ngOnInit()函数订阅此服务并显示activityIndicator,如下所示
就是这样 . 我希望这能帮到您 .