Typescript 错误 - 需要 1 个参数,但得到 0 个
Typescript error - Expected 1 arguments, but got 0
我在 Ionic/Angular 中的打字稿代码出现错误。错误输出为:
[22:55:09] typescript: C:/xampp/htdocs/project x/anonymous-social/src/pages/chat/chat.ts, line: 103
Expected 1 arguments, but got 0.
L102: if(!this.isUserThreadEmpty) {
L103: let threadKey = this.database.list('users/'+this.userData.uid+'/threads/'+this.recipient).push().key;
L104: let recipientData = {
我不知道为什么会这样,我猜 push()
需要一个论点,但我在网上看到的关于如何在 firebase 中获得 key
的所有 Whosebug 答案都指向了这个解决方案,所以我不确定发生了什么。
实际代码为:
if(!this.isUserThreadEmpty) {
let threadKey = this.database.list('users/'+this.userData.uid+'/threads/'+this.recipient).push().key;
let recipientData = {
recipient: this.recipient,
threadId: threadKey,
displayName: this.displayName,
}
有什么想法吗?我需要将 key
传递给 recipientData
...我做错了什么?
您正在使用 AngularFire2。 push
method in AngularFire2 需要一个参数。
您链接的问题和文档适用于常规 Firebase JavaScript SDK,其中 push
的参数是可选的。
您最好的选择是使用常规 JavaScript SDK 来执行此操作,因为通过 AngularFire2 包装器执行此操作没有任何优势:
let threadKey = firebase.database().ref().push().key;
来自 Jane 的评论:要使用 Firebase JavaScript SDK,您需要:
import * as firebase from 'firebase/app';
更新(2018-06-08):我刚刚发现还有一个创建推送ID的专用方法AngularFireDatabase.createPushId()
。所以我认为你的情况是 database.createPushId()
.
我在 Ionic/Angular 中的打字稿代码出现错误。错误输出为:
[22:55:09] typescript: C:/xampp/htdocs/project x/anonymous-social/src/pages/chat/chat.ts, line: 103 Expected 1 arguments, but got 0.
L102: if(!this.isUserThreadEmpty) {
L103: let threadKey = this.database.list('users/'+this.userData.uid+'/threads/'+this.recipient).push().key;
L104: let recipientData = {
我不知道为什么会这样,我猜 push()
需要一个论点,但我在网上看到的关于如何在 firebase 中获得 key
的所有 Whosebug 答案都指向了这个解决方案,所以我不确定发生了什么。
实际代码为:
if(!this.isUserThreadEmpty) {
let threadKey = this.database.list('users/'+this.userData.uid+'/threads/'+this.recipient).push().key;
let recipientData = {
recipient: this.recipient,
threadId: threadKey,
displayName: this.displayName,
}
有什么想法吗?我需要将 key
传递给 recipientData
...我做错了什么?
您正在使用 AngularFire2。 push
method in AngularFire2 需要一个参数。
您链接的问题和文档适用于常规 Firebase JavaScript SDK,其中 push
的参数是可选的。
您最好的选择是使用常规 JavaScript SDK 来执行此操作,因为通过 AngularFire2 包装器执行此操作没有任何优势:
let threadKey = firebase.database().ref().push().key;
来自 Jane 的评论:要使用 Firebase JavaScript SDK,您需要:
import * as firebase from 'firebase/app';
更新(2018-06-08):我刚刚发现还有一个创建推送ID的专用方法AngularFireDatabase.createPushId()
。所以我认为你的情况是 database.createPushId()
.