使用离子2加载组件时出现此错误
error_handler.js:54 EXCEPTION:Uncaught(在promise中):TypeError: n.apply不是函数TypeError:n.apply不是函数
我的代码
constructor(public http: Http,public loadingCtrl: LoadingController){
this.loader = this.loadingCtrl.create({
content: "Please wait...",
dismissOnPageChange: false,
duration: 3000,
});
}
ionViewDidLoad()
{
let url = this.shareServices.URL+'get_nonce/?controller=user&method=register';
// let body = '?controller=user&method=register';
let body = {
controller : 'user',
method : 'register',
}
let headers = new Headers({
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
});
let options = new RequestOptions({
headers: headers,
});
this.loader.present().then(
this.http.post(url, body, options).map(res => res.json()).subscribe(
nonce => {
this.nonceResp = nonce;
this.loader.dismissAll();
// console.log(this.nonceResp.nonce);
},
err => {
console.log(err);
let toast = this.toastCtrl.create({
message: 'Error Loading Nonce',
duration: 3000
});
toast.present();
this.navCtrl.push(LoginPage);
}
)
);
}
答案 0 :(得分:0)
present()方法是否返回一个promise? 在official docs中,从不使用present()的返回
您可以将其重写为
this.loader.present()
this.http.post(url, body, options)
作为同步代码。