我收到以下错误消息:
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
管道,则会遇到相同的错误。我已经尝试过这个问题,但没有成功:
Angular 4: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
知道我在做什么错吗?预先感谢。
答案 0 :(得分:0)
这是从angularfire2检索数据的旧方法,现在我可以使用它:
在我的组件中:
...
export class HomePage implements OnInit {
shoppingList$: Observable<Item[]>
constructor(
public navCtrl: NavController,
private shopping: ShoppingListService
) {}
ngOnInit() {
this.shoppingList$ = this.shopping
.getShoppingList()
.valueChanges();
}
...
一切正常。