无法读取未定义的Angular Firebase的属性“ push”

时间:2018-10-11 16:06:54

标签: angular typescript firebase

**无法读取未定义的Angular Firebase的属性“ push” **

import { Injectable } from '@angular/core';
import {FormControl,FormGroup, Validators} from '@angular/forms';
import {AngularFireDatabase, AngularFireList} from 'angularfire2/database';
@Injectable()
export class QuestionService {

  constructor(private firebase: AngularFireDatabase) { }
  questionList:AngularFireList<any>;


  form = new FormGroup({
    $key: new FormControl(null),
    newQuestion: new FormControl('', Validators.required)

  });

  getQuestions(){
    this.questionList = this.firebase.list('questions');
    return this.questionList.snapshotChanges();
  }

  insertQuestion(question){
    this.questionList.push({
      newQuestion: question.newQuestion
    });
  }

}

尝试将数据推送到Firebase,但遇到此错误。

1 个答案:

答案 0 :(得分:1)

只需初始化您的列表

celery=4.2.1
rabbitmq=3.7.7
python=3.6.5