【发布时间】:2021-10-26 01:16:48
【问题描述】:
我的QuestionService 文件中有一个函数:
updateQuestion(question: Question){
return new Promise<any>((resolve, reject) =>{
this.db.database.ref(`questions/${question.key}`)
.update(question)
});
}
但是,当从我的 questions.component.ts 文件中调用时,.then() 末尾有一个 .then() 不会被执行:
this.questionsService.updateQuestion(this.question).then(res =>{
console.log('success editing the question') //not being logged
this.messageService.add({severity:'success', summary: 'Successful', detail: 'Question Updated', life: 3000});
}).catch(error => {
console.log(error);
this.messageService.add({severity:'error', summary:'Error', detail:'There has been an error'})
})
请注意,如果我在service 文件中添加.then(),它将正常执行:
updateQuestion(question: Question){
return new Promise<any>((resolve, reject) =>{
this.db.database.ref(`questions/${question.key}`)
.update(question)
.then(res => {
console.log('question was updated'); //is logged
}, err => {
reject(err)
});
});
}
有人知道为什么会这样吗?
【问题讨论】: