在离子cordova构建android上获得错误 [英] Getting error on ionic cordova build android
本文介绍了在离子cordova构建android上获得错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
刚刚开始学习离子3.在上面获取以下错误离线cordova build android
Just started to learn ionic 3. Getting below error on ionic cordova build android
(node:6364) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): [object Object]
(node:6364) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
以下是我的离子信息。
cli packages: (C:\Users\HIT\AppData\Roaming\npm\node_modules)
@ionic/cli-utils : 1.19.0
ionic (Ionic CLI) : 3.19.0
global packages:
cordova (Cordova CLI) : 8.0.0
local packages:
@ionic/app-scripts : 3.1.6
Cordova Platforms : none
Ionic Framework : ionic-angular 3.9.2
System:
Node : v8.5.0
npm : 5.3.0
OS : Windows 10
Environment Variables:
ANDROID_HOME : D:\AndroidSdk\platform-tools
Misc:
backend : pro
我写下面的承诺代码
postData(credentials, type) {
return new Promise((resolve, reject) => {
let headers = new Headers();
this.http.post(apiUrl+type, JSON.stringify(credentials), {headers: headers})
.subscribe(res => {
resolve(res.json());
}, (err) => {
reject(err);
});
});
}
我调用 postData
下面的函数
signup(){
//Api connection
this.authService.postData(this.userData , "register.php").then((result) => {
this.reposeData = result;
console.log(this.reposeData);
localStorage.setItem('userData' , JSON.stringify(this.reposeData))
this.navCtrl.push(TabsPage);
}, (err) => {
//connection failed
});
}
这是我的代码问题?
推荐答案
根据错误消息,您尚未处理对某个Promise对象的拒绝。每个承诺都应该有一个.catch(...)。
According to the error message, you have not handled a rejection on one of your Promise objects. Each and every promise is expected to have a .catch(...).
var flag = false;
var Test = function () {
return new Promise(function (resolve, reject) {
if (flag === true)
resolve();
else
reject();
});
}
var testFunc = Test();
testFunc.then(function () {
alert("Promise Resolved");
});
testFunc.catch(function () {
alert("Promise Rejected");
});
了解有关Promise Objects的更多信息 here
Read more about Promise Objects here
这篇关于在离子cordova构建android上获得错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文