-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular Firestore - serverTimestamp #1205
Comments
Seems to work if you import all of firebase...
|
maaan.. I'm getting mad at this. `private clientsCollection: AngularFirestoreCollection;
Look at this, it is a simple add ObjectModel to collection, but when I try to execute it I receive this:
It is almost the same as your piece of code, but it does not work :/ |
@eduardowickertg I don't think you issue is related to this issue. |
@eduardowickertg I have the same problem and I'm getting mad, @Toxicable Do you have a simple solution? |
@Wanted92 @eduardowickertg I explained what's going on here #1215 (comment) |
@stubborncoder does your add method work? Without the the time stamp? I followed the docs and didn’t use the second line where you use “return xxxx”. Maybe that’s why my add method is broken. |
@stubborncoder I think I found something that you could try for timestamps. It works for me wonderfully! import { Component, OnInit } from '@angular/core';
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
import * as firebase from 'firebase';
import { Observable } from 'rxjs/Observable';
export interface Announcement { id: string; title: string; body: string, createdAt: Date }
@Component({
selector: 'app-announcement-form',
templateUrl: './announcement-form.component.html',
styleUrls: ['./announcement-form.component.css']
})
export class AnnouncementFormComponent implements OnInit {
private announcementCollection: AngularFirestoreCollection<Announcement>;
announcements: Observable<Announcement[]>;
constructor(private afs: AngularFirestore) {
this.announcementCollection = afs.collection<Announcement>('announcements');
this.announcements = this.announcementCollection.valueChanges();
}
ngOnInit() {
console.log("Hello");
}
addAnnouncement(title: string, body: string){
const id = this.afs.createId();
const createdAt = new Date();
console.log(createdAt);
const announcement: Announcement = {id: id, title: title, body:body, createdAt: createdAt };
console.log(announcement);
this.announcementCollection.add(announcement);
}
} |
@callen5914 yes my method works without the timestamp line, your suggestion works fine but bear in mind that you are saving the client's date value, and I would like that field to be more reliable to avoid messing with ordering that collection for example. With new Date() you will set the date to whatever date you user has in her computer... Sorry I loged as another user, I'm still the original poster. |
I'm also having this issue as @stubborncoder. I'm working in Ionic 3 and I've imported angularfire2 and the Firestore module but when I call
I get property "FieldValue" does not exist on type Firestore when I call:
|
As @sionfletcher stated some days ago, you have to use the whole firebase thingy, the service approach here does not work for some reason: import * as firebase from ‘firebase’; |
Just a small improvement for going to production with Firestore. import * as firebase from 'firebase/app'; ticket.createdAt = firebase.firestore.FieldValue.serverTimestamp(); |
|
even cleaner: ticket.createdAt = firestore.FieldValue.serverTimestamp(); |
This is useful, but it's not at all easy to test. |
any update in 2022? pls |
This works for me (with version:
With this, you don't need to explicitly install the firebase package. |
@BarnT Thanks, man! Finally, this worked for me (even though I'm using angular/fire 7.4) |
Hello, trying to figure out how to get a server timestamp with angularfire2/firestore,
I tried this but it does not work:
Is there any other way to set the server timestamp in a document field?.
The text was updated successfully, but these errors were encountered: