Ionic 3、Firebase 和 angularfire2 出错
Error with Ionic 3, Firebase and angularfire2
我收到以下错误消息:
ERROR Error: Uncaught (in promise): Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
当我尝试从我的 firebase 数据库中列出数据时,我不知道为什么。查看我的代码,我的相关部门:
"@ionic-native/core": "~4.9.2",
...
"angularfire2": "^5.0.0-rc.11",
"firebase": "^5.2.0",
"ionic-angular": "3.9.2",
"rxjs": "^6.2.2",
"rxjs-compat": "^6.2.2",
我的服务:
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Item } from './../../models/item/item.model';
@Injectable()
export class ShoppingListService {
private shoppingListRef;
constructor(private db: AngularFireDatabase) {
this.shoppingListRef = this.db.list<Item>('shopping-list');
}
getShoppingList() {
return this.shoppingListRef;
}
}
我的组件:
...
export class HomePage implements OnInit {
shoppingList$: Observable<Item[]>
constructor(
public navCtrl: NavController,
private shopping: ShoppingListService
) {}
ngOnInit() {
this.shoppingList$ = this.shopping
.getShoppingList()
.snapshotChanges()
.subscribe(changes => {
return changes.map(change => {
let retorno = {
key: change.payload.key,
...change.payload.val()
};
return retorno;
});
});
}
...
最后是我的模板:
<ion-item *ngFor="let item of shoppingList$ | async">
{{item.name}}
</ion-item>
如果删除 async
管道,我会遇到同样的错误。我试过这个问题但没有成功:
知道我做错了什么吗?提前致谢。
那是从 angularfire2 中检索数据的旧方法,现在我只用它来工作:
在我的组件中:
...
export class HomePage implements OnInit {
shoppingList$: Observable<Item[]>
constructor(
public navCtrl: NavController,
private shopping: ShoppingListService
) {}
ngOnInit() {
this.shoppingList$ = this.shopping
.getShoppingList()
.valueChanges();
}
...
一切正常。
我收到以下错误消息:
ERROR Error: Uncaught (in promise): Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
当我尝试从我的 firebase 数据库中列出数据时,我不知道为什么。查看我的代码,我的相关部门:
"@ionic-native/core": "~4.9.2",
...
"angularfire2": "^5.0.0-rc.11",
"firebase": "^5.2.0",
"ionic-angular": "3.9.2",
"rxjs": "^6.2.2",
"rxjs-compat": "^6.2.2",
我的服务:
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Item } from './../../models/item/item.model';
@Injectable()
export class ShoppingListService {
private shoppingListRef;
constructor(private db: AngularFireDatabase) {
this.shoppingListRef = this.db.list<Item>('shopping-list');
}
getShoppingList() {
return this.shoppingListRef;
}
}
我的组件:
...
export class HomePage implements OnInit {
shoppingList$: Observable<Item[]>
constructor(
public navCtrl: NavController,
private shopping: ShoppingListService
) {}
ngOnInit() {
this.shoppingList$ = this.shopping
.getShoppingList()
.snapshotChanges()
.subscribe(changes => {
return changes.map(change => {
let retorno = {
key: change.payload.key,
...change.payload.val()
};
return retorno;
});
});
}
...
最后是我的模板:
<ion-item *ngFor="let item of shoppingList$ | async">
{{item.name}}
</ion-item>
如果删除 async
管道,我会遇到同样的错误。我试过这个问题但没有成功:
知道我做错了什么吗?提前致谢。
那是从 angularfire2 中检索数据的旧方法,现在我只用它来工作:
在我的组件中:
...
export class HomePage implements OnInit {
shoppingList$: Observable<Item[]>
constructor(
public navCtrl: NavController,
private shopping: ShoppingListService
) {}
ngOnInit() {
this.shoppingList$ = this.shopping
.getShoppingList()
.valueChanges();
}
...
一切正常。