Angularfire: FieldValue and its increment methods

Created on 28 Mar 2019  路  6Comments  路  Source: angular/angularfire

Incrementing number fields is multi-step process now. In last firebase javascript api FieldValue.increment has been added, I feel its good to add that feature in angularfire2 too.

https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/FieldValue

Most helpful comment

too bad I still have to import firebase

All 6 comments

Incrementing will work in AngularFire today, you just need to upgrade your Firebase dependency.

How?

Is this working? I don't see this.afStore.firestore.FieldValue.increment available. Am I doing something wrong?

Y'all will have to use the JS SDK for that part

import { Component, OnInit } from '@angular/core';
import { AngularFirestore } from '@angular/fire/firestore';
import * as firebase from 'firebase/app';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
  constructor(private readonly af: AngularFirestore) {}

  async ngOnInit() {
    await this.af.collection('test').add({
      test: firebase.firestore.FieldValue.increment(1),
    });
  }
}

too bad I still have to import firebase

is there any way to use FieldValue.increment without using firebase import?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jteplitz picture jteplitz  路  3Comments

aucevica picture aucevica  路  3Comments

harrylincoln picture harrylincoln  路  3Comments

cre8 picture cre8  路  3Comments

Leanvitale picture Leanvitale  路  3Comments