【发布时间】:2019-09-17 00:09:08
【问题描述】:
我试图在一个 promise 中返回一个 promise 函数的值。仍然很新的承诺,所以任何建议都非常感谢!
// card.service.ts
getCard(cardId: string): DocumentData {
return firebase.firestore().collection('users').doc(this.currentUserId)
.collection('cardsList').doc(cardId)
.get()
.then((docSnapShot) => {
console.log((docSnapShot));
return docSnapShot.data();
},
(err) => {
console.log(err);
});
}
addCardToWallet(userId: string, cardId: string, dataObject: DocumentData) {
return firebase.firestore().collection('users').doc(userId)
.collection('walletList')
.doc(cardId)
.set(
dataObject
);
}
// scanner.component.ts
scanCode() {
this.barcodeScanner.scan(
{
showFlipCameraButton : true, // iOS and Android
showTorchButton : true, // iOS and Android
prompt : 'Scan a Kardbox QR' // Android
}
).then((barcodeData) => {
this.cardService.getCard(barcodeData.text)
.then((data) => {
// I want to add this to the database first
this.cardService.addCardToWallet(this.currentUserId, barcodeData.text, data);
// After adding values to database, navigate to other page
this.router.navigate(['/home/wallet']);
});
});
}
我得到的输出是barcodeData 的值,我不知道为什么会这样。
【问题讨论】:
-
我得到的输出是什么意思?该输出在调用
scanCode()方法的方法中? -
是的,你是对的!
-
你想从
scanCode()返回什么结果?
标签: angular typescript firebase google-cloud-firestore ionic4