Angular2 및 Firebase 웹 응용 프로그램 (CRUD)을 만들려고합니다. 새 비즈니스 사용자를 추가하려고하면 오류가 발생합니다.Angular2/Firebase - 예외 : TypeError : 정의되지 않은 'push'속성을 읽을 수 없습니다.
appComponent.ts 파일 :
import { Component, OnInit} from '@angular/core';
import { AngularFire, FirebaseListObservable } from 'angularfire2';
import {FirebaseService} from './services/firebase.service';
import 'rxjs/add/operator/map';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
providers:[FirebaseService]
})
export class AppComponent implements OnInit {
title = 'app works';
BusinessUsers : Business[];
categories : Category[];
appState: string;
activeKey: string;
constructor(private _firebaseService:FirebaseService) {
}
ngOnInit(){
this.appState = 'default';
this._firebaseService.getBusinessUsers().subscribe(BusinessUsers => {
this.BusinessUsers = BusinessUsers
});
this._firebaseService.getCategories().subscribe(categories => {
this.categories = categories
});
}
changeState(state, key = null){
if(key){
this.activeKey = key;
}
this.appState = state;
}
addBusiness(
website: URL,
){
var created_at = new Date().toString();
var newBusiness = {
website: website,
created_at:created_at
}
this._firebaseService.addBusiness(newBusiness);
this.changeState('default');
}
}
export interface Business {
$Key:string;
address: string;
company?: string;
zipcode: number;
suite: Date;
email: string;
name: string;
website: URL;
}
export interface Category {
$Key:string;
value: string;
}
firebase.service.ts
파일에서 : 나는 텍스트를 작성하고 추가를 클릭하면
import {Injectable} from '@angular/core';
import { AngularFire, FirebaseListObservable } from 'angularfire2';
@Injectable()
export class FirebaseService{
BusinessUsers : FirebaseListObservable<Business[]>;
categories : FirebaseListObservable<Category[]>;
constructor(private af:AngularFire) {
}
getBusinessUsers(){
this.BusinessUsers = this.af.database.list('/BusinessUsers') as FirebaseListObservable<Business[]>;
return this.BusinessUsers;
}
getCategories(){
this.categories = this.af.database.list('/Categories') as FirebaseListObservable<Category[]>;
return this.categories;
}
addBusiness(newBusiness): Promise<any>{
return this.businessUsers.push(newBusiness);
}
}
export interface Business {
$Key:string;
address: string;
company?: string;
zipcode: number;
suite: Date;
email: string;
name: string;
website: URL;
}
export interface Category {
$Key:string;
value: string;
}
이 오류의 이미지 :
나는 Firebase 데이터베이스를 가지고 있습니다.
의미! –