财产'捕获'在' PromiseLike& lt; void& gt;类型上不存在
我在以下代码中遇到此错误.我正在使用ionic3:
I'm getting this error in the following code. I'm using ionic3:
类型为"PromiseLike"的属性捕获"不存在
这是我正在关注的教程的链接.
This is the link to the tutorial that I am following.
此错误显示在VS代码中.
This error is showing in the VS Code.
这可能是我不知道的一些更新语法
This probably some updated syntax I'm not aware of
storetoken(t) {
this.afd.list(this.firestore).push({
uid: firebase.auth().currentUser.uid,
devtoken: t
}).then(() => {
alert('Token stored');
})
.catch(() => {
alert('Token not stored');
})
this.afd.list(this.firemsg).push({
sendername: 'vivek',
message: 'hello'
}).then(() => {
alert('Message stored');
})
.catch(() => {
alert('Message not stored');
})
}
**这是将令牌发送到Firebase数据库的home.ts文件的完整代码:也请参考此代码,因为我也遇到另一个错误:错误:未捕获(承诺):错误:StaticInjectorError [当我删除catch块时. **
**This is the entire code for the home.ts file which sends token onto firebase database:Please refer this as well, as i'm also getting another error:Error: Uncaught (in promise): Error: StaticInjectorError[AngularFireDatabase] when I remove the catch block. **
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AngularFireDatabase } from 'angularfire2/database';
import firebase from 'firebase';
import { HttpClientModule } from '@angular/common/http';
import { HttpModule } from '@angular/http';
declare var FCMPlugin;
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
firestore = firebase.database().ref('/pushtokens');
firemsg = firebase.database().ref('/messages');
constructor(public navCtrl: NavController, public afd:
AngularFireDatabase) {
this.tokensetup().then((token) => {
this.storetoken(token);
})
}
ionViewDidLoad() {
FCMPlugin.onNotification(function(data){
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
alert( JSON.stringify(data) );
}else{
//Notification was received in foreground. Maybe the user needs to be
notified.
alert( JSON.stringify(data) );
}
});
FCMPlugin.onTokenRefresh(function(token){
alert( token );
});
}
tokensetup() {
var promise = new Promise((resolve, reject) => {
FCMPlugin.getToken(function(token){
resolve(token);
}, (err) => {
reject(err);
});
})
return promise;
}
storetoken(t) {
this.afd.list(this.firestore).push({
uid: firebase.auth().currentUser.uid,
devtoken: t
}).then(() => {
alert('Token stored');
}).catch(() => {
alert('Token not stored');
})
this.afd.list(this.firemsg).push({
sendername: 'vivek',
message: 'hello'
}).then(() => {
alert('Message stored');
}).catch(() => {
alert('Message not stored');
})
}
}
承诺与参考相结合;可以在写入完成后解决,但可以立即用作对子位置的引用.
Combined Promise and Reference; resolves when write is complete, but can be used immediately as the Reference to the child location. 这意味着您可以将其用作将来对书面数据的参考. It means you can use it as a future reference to the written data. 另请参见代码库.
ThenableReference Def 在这里. See also in codebase.
ThenableReference Def here. 或者您可以采用推荐的方式,即:
您目前无法使用catch. Or you can do the recommended way i.e:
You cannot use catch currently. 注意:此处有一个未解决的问题
export interface ThenableReference extends Reference, PromiseLike<Reference> {}
this.afd.list(this.firestore).push({ uid: firebase.auth().currentUser.uid, devtoken: t });
Note: There is an open issue here if you want to follow it.