2016-12-06 3 views
1

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; 
} 

이 오류의 이미지 :

enter image description here

나는 Firebase 데이터베이스를 가지고 있습니다.

+0

의미! –

답변

0

명명 규칙 문제입니다. 서비스 파일에

businessUsers : FirebaseListObservable<Business[]>; 

BusinessUsers : FirebaseListObservable<Business[]>; 

교체합니다. 여기 기업 사용자이어야합니다. 사용자는이어야합니다. 희망이 작동합니다.

+0

잘 작동하지만 빨간색 줄이 나타납니다 this.businessUsers.push (newBusiness); –

+0

당신은'this.BusinessUsers'를 사용하고있는 다른 곳을 대체해야합니다. –

+0

당신을 위해 일하고 있습니까? –

관련 문제