【发布时间】:2019-03-16 19:08:47
【问题描述】:
** 无法读取未定义 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 但遇到此错误。
【问题讨论】:
-
你没有初始化。这就是它发生的原因
标签: angular typescript firebase