shin10kudev / angular-gengo-app

Japanese language learning app built in Angular4 w/angularFirebase2 and Firebase realtime db
2 stars 0 forks source link

add better namespace to upload name #14

Open shin10kudev opened 7 years ago

shin10kudev commented 7 years ago

Suggested by another user:

SERVICE
import { Injectable, Inject } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';

@Injectable()
export class FirebaseUtilityService {

    newKey: string;

    constructor(private db: AngularFireDatabase) { }

    createUniqueKey(model: string): string {
        return this.newKey = this.db.app.database().ref(model).push().key;
    }
}

USING THE SERVICE
this.$key = this.generateNewKey(firebaseRef);

generateNewKey(firebaseRef: string): string {
        return this.$key = this.firebaseService.createUniqueKey(firebaseRef);
    }