TypeError: Object(...) is not a function, 从 firebase 调用数据

Posted

技术标签:

【中文标题】TypeError: Object(...) is not a function, 从 firebase 调用数据【英文标题】:TypeError: Object(...) is not a function, calling data from firebase 【发布时间】:2019-02-15 10:42:12 【问题描述】:

我的 addevent.ts:

export class EventPage 

eventDetail =  as EventDetail;

eventDetailRef$: AngularFireList<EventDetail>;

constructor(public navCtrl: NavController, public navParams: NavParams, 
private database: AngularFireDatabase) 
    this.eventDetailRef$ = this.database.list('event-list');
 

addEvent( eventDetail: EventDetail) 

  this.eventDetailRef$.push(
  eventName: this.eventDetail.eventName,
  eventDesc: this.eventDetail.eventDesc,
  lat: Number(this.eventDetail.lat),
  lgt: Number(this.eventDetail.lgt)
  );

  this.eventDetail =  as EventDetail;

  this.navCtrl.pop(); 

  


我的showevent.ts:

newEventListRef$ : AngularFireList<EventDetail>;
newEventList$: Observable<EventDetail[]>;

constructor(public navCtrl: NavController, private database: 
AngularFireDatabase) 
this.tabs=["New", "Upcoming"];
this.newEventListRef$ = this.database.list<EventDetail>('event-list');
this.newEventList$ = this.newEventListRef$.valueChanges();

我的showevent.html

<ion-list>
    <ion-item *ngFor="let new of newEventList$ | async">
      <h2>new.eventName</h2>
      <h4>new.eventDesc</h4>
      <h6>new.lat</h6>
      <h6>new.lgt</h6>
    </ion-item>
  </ion-list>

问题:TypeError:Object(...) 不是函数

我无法从 firebase 调用数据,VScode 中没有红线或错误,我对 ionic 3 非常陌生,如果我犯了最简单的错误,请原谅。

堆栈跟踪:

TypeError: Object(...) is not a function
    at SwitchMapSubscriber.project (http://localhost:8100/build/vendor.js:78721:76)
    at SwitchMapSubscriber._next (http://localhost:8100/build/vendor.js:62701:27)
    at SwitchMapSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18)
    at RefCountSubscriber.Subscriber._next (http://localhost:8100/build/vendor.js:20786:26)
    at RefCountSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18)
    at Subject.next (http://localhost:8100/build/vendor.js:23237:25)
    at ConnectableSubscriber.Subscriber._next (http://localhost:8100/build/vendor.js:20786:26)
    at ConnectableSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18)
    at Notification.observe (http://localhost:8100/build/vendor.js:52585:50)
    at AsyncAction.DelaySubscriber.dispatch (http://localhost:8100/build/vendor.js:81001:40)

【问题讨论】:

你有错误的堆栈跟踪吗? 对不起,我马上编辑它 【参考方案1】:

请在您的项目中升级rxjs,您还必须包含rxjs-compat。请尝试以下命令:

npm i rxjs@6 rxjs-compat@6 promise-polyfill --save

您还必须在检索列表数据时使用订阅,如下所示:

this.database.list<EventDetail>('event-list').valueChanges().subscribe((eventData) => 
 
  console.log("eventDetails data", eventData);
,(err)=>
   console.log("Error while retrieving eventDetails : ", err);
); 

【讨论】:

以上是关于TypeError: Object(...) is not a function, 从 firebase 调用数据的主要内容,如果未能解决你的问题,请参考以下文章

AngularFireList' TypeError: Object(...) is not a function at SwitchMapSubscriber.project

TypeError: 'method' object is not iterable

计算数字的变体 / TypeError: 'int' object is not callable

TypeError: Object(...) is not a function, 从 firebase 调用数据

离子本地通知 TypeError: Object(...) is not a function

Python: TypeError: 'dict' object is not callable