私は角度2のコードで間違っていることを解決できません。私の約束は正しい結果を返さない。プロミスが解決しない解決
私のコードは次のようになります。this.addPlan(...)
は、サーバログと呼ばれる
this.addPlan('My plan title9', "YES9")
.then((id)=>{
console.log('Promise return was: ' + id);
})
.catch((err)=>{
console.log('Call to addPlan failed with err = ' + err);
});
addPlan(title, security)
{
let timeStamp \t = new Date().toISOString();
let plan \t \t = {
_id \t \t : 'PLAN:' + timeStamp,
title \t \t : title,
security \t : security,
notes : [],
flags : [],
created : timeStamp,
updated \t : timeStamp
};
return new Promise(resolve =>
{
var theID;
this._DB.put(plan)
.then(function (response) {
console.log(JSON.stringify(response));
resolve(response.id);
theID = response.id;
})
.catch((err) =>
{
console.log('addPlan error is: ' + err);
this.success = false;
});
if(this.success)
{
this.handleSyncing();
resolve(theID);
}
});
}
は次のとおりです。
Promise return was: undefined
{"ok":true,"id":"PLAN:2017-01-09T18:16:50.094Z","rev":"1-ac45a4785982fcbbcb46dd099431ecb6"}
それがあるべきときの約束からのリターンは定義されていません'id'の値また、コンソールにPromiseメッセージが最初に表示されますが、プロミスが返された後に表示されるはずです。
明らかに私はここで初心者のエラーを作りましたが、私はそれが何かを見ることができません。