how can i use serverTimestamp in angular/Fire in the compat mode

20 Views Asked by At

I have tried

import firebase from 'firebase/compat/app';
import 'firebase/compat/firestore';
const firestore = firebase.firestore;

this.form = this.builder.group({
      items:[data.items, null],
      dateReported:[firestore.FieldValue.serverTimestamp(), Validators.required],
    ....})

i get this error:

ERROR FirebaseError: Function WriteBatch.update() called with invalid data. Unsupported field value: a custom sl object (found in field dateReported )

{
    "items": [
        {
            "sku": "2756",
            "qty": 1,
            "name": "\tImpresora Artillery X3 Plus"
        }
    ],
    "dateReported": {
        "_methodName": "serverTimestamp"
    },
    "dateModified": {
        "_methodName": "serverTimestamp"
    },
    "trialsAndResults": "cable suelto",
    "inspectedItems": [
        {
            "sku": "2756",
            "qty": 1,
            "name": "\tImpresora Artillery X3 Plus",
            "dictum": "repair"
        }
    ],
    "status": "examined",
    "technician": "Cristobal",
    "charge": 0,
    "report": null
}

also tried

import { serverTimestamp } from 'firebase/firestore';
import { AngularFirestore } from '@angular/fire/compat/firestore';

constructor(private afs: AngularFirestore, ...) {
    this.form = this.builder.group({
        dateReported: [serverTimestamp(), Validators.required],
        ...
    });

    const batch = this.afs.firestore.batch();
    const orderRef = this.afs.firestore.collection(...).doc(....);
    batch.update(orderRef, this.form.value);
    batch.commit()
}

same error

tried

import firebase  from 'firebase/compat/app';
dateReported:[firebase.firestore.FieldValue.serverTimestamp(), Validators.required],

ERROR TypeError: Cannot read properties of undefined (reading 'FieldValue')

"@angular/compiler": "^17.3.0",
"@angular/core": "^17.3.0",
"@angular/fire": "^17.0.1",
"@angular/forms": "^17.3.0",
"@angular/material": "^17.2.2",
"firebase": "^9.23.0",
0

There are 0 best solutions below