angular - 运行时错误:Object(...) 不是函数 Ionic/Firebase/Angular
问题描述
我正在创建一个 Ionic 应用程序,其中有一个我想要显示的信息列表,我使用 Firebase 作为我的数据库(实时数据库)。
但我一直收到这个错误:
Object(...) 不是函数
而且我不确定为什么,因为代码看起来不错(我检查了 angularfire2 git 以确保)。
所以这里是代码:
列表.ts
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { AngularFireDatabase } from 'angularfire2/database';
@Component({
selector: 'page-list',
templateUrl: 'list.html'
})
export class ListPage {
informationslist:any;
constructor(public navCtrl: NavController, public navParams: NavParams,
private afDB: AngularFireDatabase) {
try{
this.informationslist = afDB.list('information', (ref) =>
ref.orderByChild('datetime')).valueChanges();
}catch(e){
console.log(e);
}
}
}
列表.html
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>List</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item *ngFor="let i of informationslist | async">{{i.title}}</ion-item>
</ion-list>
</ion-content>
解决方案
你能提供rxjs的版本吗?在大多数情况下,错误的版本可能会出现问题。我认为当前的 angularfire2 需要 rxjs 版本 6.0.0 或更高版本。完整的 javascript 堆栈也可能很有用。
此外,如果您之前使用过另一个 rxjs 版本,现在尝试升级,请考虑迁移指南:Migration guide rxjs from 5 to 6
推荐阅读
- web-component - 如何在 Vaadin Flow 中填充组件中的属性更改?
- java - 当多个用户访问 url 时,JSP 请求关闭,最后一个请求没有任何响应。可能是什么原因?
- mongodb - MongoDB - 检查对象数组中是否存在键
- android - why is my Floating Action Button onclick not working?
- forms - Typo3 Fluid - 检查单选按钮是否被选中
- javascript - Webpack 自定义插件。使用 AST 在反应组件中插入属性
- java - 将 postgres 函数文件放在类路径中并在 Spring Boot 启动事件上执行,这是个好主意吗?
- javascript - 如何正确使用 flyTo() 和 setInterval() 或 setTimeout() Javascript 函数?
- regex - 正则表达式提取一个字符的第二个实例和另一个字符的第二个实例之间的字符串
- javascript - 从对象数组中删除键值