我正在学习Ionic,所以一旦点击了Signup按钮,如何在得到离子3的回复后显示加载符号并隐藏它?
sign.html
<button ion-button color="danger" block outline (click)="signup()">Signup</button>
signup.ts
signup() {
this.authServiceProvider.postData(this.userData, "signup").then((result) => {
this.responseData = result;
console.log(this.responseData);
if( (JSON.stringify(this.responseData._body)) != "" ) {
this.navCtrl.setRoot(HomePage);
} else {
console.log("User already exists");
}
}, (err) => {
//connection failed error message
console.log("something went wrong");
});
}
发布于 2018-05-29 10:58:04
首先,您需要导入加载控制器。
import { LoadingController } from 'ionic-angular';
在构造函数中,需要创建它的一个对象。作为
constructor(public loadingCtrl: LoadingController){}
现在,在调用“注册方法”中的服务之前,您需要激活加载消息,并在结果结束后,将其关闭。
signup() {
let loading = this.loadingCtrl.create({
content: 'Please wait...'
});
loading.present();
this.authServiceProvider.postData(this.userData, "signup").then((result) => {
this.responseData = result;
console.log(this.responseData);
if( (JSON.stringify(this.responseData._body)) != "" ) {
loading.dismiss();
this.navCtrl.setRoot(HomePage);
} else {
loading.dismiss();
console.log("User already exists");
}
}, (err) => {
//connection failed error message
console.log("something went wrong");
});
}
https://stackoverflow.com/questions/50582422
复制相似问题