I am having issue getting a basic CRUD to-do list app using Ionic 3 and Firebase to work.
The error message I am stuck on is:
Uncaught (in promise): Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
The error message started when I added the <ion-item *ngFor="let item of shoppingListRef$ | async">
section to shopping-list.html:
shopping-list.html
<ion-header>
<ion-navbar color="primary">
<ion-title>Shopping List</ion-title>
<ion-buttons end>
<button ion-button icon-only (click)="navigateToAddShoppingPage()">
<ion-icon name="add"></ion-icon>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-item *ngFor="let item of shoppingListRef$ | async">
<h2>Item Name: {{item.itemName}}</h2>
<h3>Amount: {{item.itemNumber}}</h3>
</ion-item>
</ion-list>
</ion-content>
I have tried commenting out the code between <ion-item>
and </ion-item>
in the file above, and that removes the error message. However, can't figure out how to fix it.
Here are some relevant files involved.
shopping-list.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import { AddShoppingPage } from '../add-shopping/add-shopping';
import { ShoppingItem } from '../../models/shopping-item/shopping-item.interface';
@Component({
selector: 'page-shopping-list',
templateUrl: 'shopping-list.html',
})
export class ShoppingListPage {
shoppingListRef$: FirebaseListObservable<ShoppingItem[]>
constructor(public navCtrl: NavController, public navParams: NavParams, private database: AngularFireDatabase) {
this.shoppingListRef$ = this.database.list('shopping-list');
}
navigateToAddShoppingPage() {
this.navCtrl.push(AddShoppingPage)
}
}
shopping-item.interface.ts
export interface ShoppingItem {
itemName: string;
itemNumber: number;
}
Thanks in advance for any ideas / help you may have!
I think you are using the new angularfire2 version which is version 5 in this case you should be doing the following:
import { Component } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';
@Component({
selector: 'page-shopping-list',
templateUrl: 'shopping-list.html',
})
export class ShoppingListPage {
shoppingListRef$: Observable<any[]>;
constructor(database: AngularFireDatabase) {
this.shoppingListRef$ = this.database.list('shopping-list').valueChanges();;
}
}
as starting from version 5 database.list
no longer returns an observable so you can't subscribe to it in the template using the async
pipe. this is why you should chain the valueChanges()
method which returns an Observable in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With