简体   繁体   中英

IONIC 3 - TypeError: Object(…) is not a function

I'm newbie on Ionic with Firebase, I have this error when I run the app :

TypeError: Object(...) is not a function

That's the different part of codes :

In 'ts' file :

items : AngularFireList<any[]>; 
itemArray = [];

this.items = afs.list("persons");

this.items.snapshotChanges().subscribe(actions =>{
actions.forEach(action=>{
let y = action.payload.toJSON();
y['$key'] = action.key;
this.itemArray.push(y as Person);
})
})

Html :

<ion-item-sliding *ngFor = "let person of itemArray"> 
...

I've installed a latest version of firebase and angularfire2 :

npm install firebase angularfire2 --save
npm install @firebase/app@latest --save

Current configuration in app.module.ts :

"angularfire2": "^5.0.0-rc.11",
    "firebase": "^5.3.0",
    "ionic-angular": "3.9.2",
    "ionicons": "3.0.0",
    "rxjs": "5.5.11",

Make sure your function calls return non-null values:

items : AngularFireList<any[]>; 
itemArray = [];

this.items = afs.list("persons");

if(this.items){
    this.items.snapshotChanges().subscribe(actions =>{
      actions.forEach(action=>{
        if(action && action.payload){
           let y = action.payload.toJSON();
           y['$key'] = action.key;
           this.itemArray.push(y as Person);
       }
    })
})

As a side note I recommend not using angularfire. In my experience, it was a headache maintaining and updating it. Firebase SDK itself provides enough functionality for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM