首页 文章

Nativescript:在页面转换过程中显示ActivityIndicator

提问于
浏览
0

我正在使用Nativescript Typescript / Angular2 .

我有一个非常繁重的页面加载(它包含一个tabview和一个 Map )所以我想在点击引用页面的routerlink时显示一个ActivityIndicator,并在加载页面时隐藏它 . 我想我可能会利用 Page 类的 load 事件(如上所述here)来实现它,但是在文档中它还不清楚如何在Angular Nativescript中执行它 . 谁能提供一个例子吗?

1 回答

  • 0

    转到要显示ActivityIndicator的页面并在顶部添加:

    <ActivityIndicator [busy]="isLoading" [visibility]="isLoading ? 'visible' : 'collapse'" row="1" horizontalAlignment="center" verticalAlignment="center"></ActivityIndicator>
    

    您必须在此页面的组件中创建名为isLoading的新属性,并将其初始化为false:

    isLoading = false;
    

    现在您拥有了这个属性,最后一步是在加载数据时将此属性设置为true以显示加载器 . 这将根据您的实现而有所不同 . 但是为了便于解释,我们可以考虑编写一些处理数据的服务,我们在组件中订阅它 . 我将利用ngOnInit()函数订阅此服务并显示activityIndicator,如下所示

    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.
        });
    }
    

    就是这样 . 我希望这能帮到您 .

相关问题