Angularfire: Generate a Id and then use it with set operation

Created on 20 Jul 2018  路  1Comment  路  Source: angular/angularfire

Version info

This most likely not an error but I can't figure out how to solve my problem and I couldn't find anything that actually helped me in other posts.

Angular: 6.0.3

Firebase: 5.2.0

AngularFire: 5.0.0-rc.11

Other (e.g. Ionic/Cordova, Node, browser, operating system): No

How to reproduce these conditions

Steps to set up and reproduce

const key = this.db.createId;
this.categoiresRef.doc(key).set({'test' : 'test'});

Actual behavior

I get the Syntax Error: Argument of type '(this: Function, thisArg: any, argArray?: any) => any' is not assignable to parameter of type 'string'.

I expected that createId would me a random generated Id as a String with which I could set a Document in a Collection. I want to get the Key before pushing my Object. I know that this works with java but I can麓t figure out how to do it in AngularFire.

Most helpful comment

I think you are missing some brackets.

constructor(public readonly afs: AngularFirestore) {}


    doc.id = this.afs.createId();

>All comments

I think you are missing some brackets.

constructor(public readonly afs: AngularFirestore) {}


    doc.id = this.afs.createId();
Was this page helpful?
0 / 5 - 0 ratings

Related issues

cre8 picture cre8  路  3Comments

StephenFluin picture StephenFluin  路  3Comments

fisherds picture fisherds  路  3Comments

aucevica picture aucevica  路  3Comments

DennisSmolek picture DennisSmolek  路  3Comments