Угловой и пожарный [толчок не функция] - PullRequest
0 голосов
/ 10 сентября 2018

У меня ошибка с Angular и firebase:

ОШИБКА TypeError: _this.accounts.push не является функцией на auth.service.ts: 25 например, (auth.esm.js: 17) в Fb (auth.esm.js: 20) на Bb (auth.esm.js: 20) в A.push ../ node_modules/@firebase/auth/dist/auth.esm.js.g.Xb (auth.esm.js: 19) в кб (auth.esm.js: 13) в ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invoke (zone.js: 388) в Object.onInvoke (core.js: 3824) в ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invoke (zone.js: 387) в Zone.push ../ node_modules / zone.js / dist / zone.js.Zone.run (zone.js: 138)

auth.service.ts:

import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { Account } from '../models/Account.model'
import * as firebase from 'firebase';
import DataSnapshot = firebase.database.DataSnapshot;

@Injectable({
    providedIn: 'root'
})
export class AuthService {

    accounts: Account[] = [];
    accountsSubject = new Subject<Account[]>;

    constructor() {
        this.getAccounts();
    }

    createNewUser(email: string, password: string, newAccount: Account) {
        return new Promise(
            (resolve, reject) => {
                firebase.auth().createUserWithEmailAndPassword(email, password).then(
                    () => {
                        resolve();
                        this.accounts.push(newAccount); // <-- 25
                        this.saveAccounts();
                        this.emitAccounts();
                    },
                    (error) => {
                        reject(error);
                    }
                    );
            }
            );
    }
    emitAccounts(){
        this.accountsSubject.next(this.accounts);
    }
    saveAccounts(){
        firebase.database().ref('/accounts').set(this.accounts);
    }
    getAccounts(){  
        firebase.database().ref('/accounts')
        .on('value', (data: DataSnapshot) => {
            this.accounts = data.val() ? data.val() : [];
            this.emitAccounts();
        }
        );
    }
    signInUser(email: string, password: string) {
        return new Promise(
            (resolve, reject) => {
                firebase.auth().signInWithEmailAndPassword(email, password).then(
                    () => {
                        resolve();
                    },
                    (error) => {
                        reject(error);
                    }
                    );
            }
            );
    }

    signOutUser() {
        firebase.auth().signOut();
    }

}

Спасибо в аванс. Жереми

...