nis*_*ave 5 ionic-framework ionic3
在组件中创建博客和文章加载器中的所有位置。我需要一次创建一个加载程序,并在整个应用程序中使用它。但是问题是,在ionic 3中,我们无法手动关闭加载程序。出现以下正确代码后,应将其关闭:
ionViewLoaded() {
let loader = this.loading.create({
content: 'Getting latest entries...',
});
loader.present().then(() => {
this.someService.getLatestEntries()
.subscribe(res => {
this.latestEntries = res;
});
loader.dismiss();
});
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用服务创建一次加载程序,并在需要整个应用程序时使用它。如:
import {Injectable} from '@angular/core';
import { LoadingController } from 'ionic-angular';
@Injectable()
export class BasicService{
loader: any;
constructor(public loadingCtrl: LoadingController){
//creates loader once so there is less data redundancy
this.loader = this.loadingCtrl.create({
content: `loading...`,
});
}
showLoader() { //call this fn to show loader
this.loader.present();
}
hideLoader() { //call this fn to hide loader
this.loader.dismiss();
}
}
Run Code Online (Sandbox Code Playgroud)
但是它不起作用,并给出诸如这样的错误。
未捕获运行时错误(承诺):找不到removeView
那么,有什么方法可以在ionic 3中实现这一壮举,从而帮助我实现数据冗余?
constructor(public loadingCtrl: LoadingController){
//creates loader once so there is less data redundancy
}
showLoader() { //call this fn to show loader
this.loader = this.loadingCtrl.create({
content: `loading...`,
});
this.loader.present();
}
Run Code Online (Sandbox Code Playgroud)
LoadingController
从控制器中删除创建实例并将其添加到showLoader()
服务的函数中。
归档时间: |
|
查看次数: |
1845 次 |
最近记录: |