Events Nativescript:在进行页面转换时显示ActivityIndicator

Events Nativescript:在进行页面转换时显示ActivityIndicator,events,navigation,nativescript,angular2-nativescript,nativescript-angular,Events,Navigation,Nativescript,Angular2 Nativescript,Nativescript Angular,我正在使用Nativescript+Typescript/Angular2 我有一个很难加载的页面(它包含一个tabview和一个map),所以我想在点击引用页面的routerlink时显示ActivityIndicator,并在加载页面时隐藏它。我想我可能会利用页面类的加载事件(如前所述)来实现它,但在文档中不清楚如何在Angular Nativescript中实现它。有人能提供一个例子吗?转到要显示其ActivityIndicator的页面,并在顶部添加: <ActivityIndic

我正在使用Nativescript+Typescript/Angular2


我有一个很难加载的页面(它包含一个tabview和一个map),所以我想在点击引用页面的routerlink时显示ActivityIndicator,并在加载页面时隐藏它。我想我可能会利用
页面
类的
加载
事件(如前所述)来实现它,但在文档中不清楚如何在Angular Nativescript中实现它。有人能提供一个例子吗?

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

<ActivityIndicator [busy]="isLoading" [visibility]="isLoading ? 'visible' : 'collapse'" row="1" horizontalAlignment="center" verticalAlignment="center"></ActivityIndicator>
既然您有了这个属性,最后一步就是在加载数据时将这个属性设置为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.
    });
}

就这样。我希望这对你有帮助

问题正是实现以及绑定isLoading属性的内容。不幸的是,我不需要将微调器挂接到任何类型的数据加载开始/结束或外部服务异步活动,而是挂接到页面加载和呈现本身。因此,我想,在这种情况下,ngOnInit()生命周期是无用的,因为它是在初始化完成后由角度组件触发的。让我试着更好地解释一下:我需要在触发从页面a到页面B的页面转换后显示加载(当用户点击页面上的listitem时)直到页面转换完成。现在正是平台解析路由条目并将新页面放入框架的时候。因此,当用户仍在查看页面时,可能会显示微调器ADid您找到解决方案了吗?我正在寻找相同的,但使用的是
nativescript vue
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.
    });
}