Adam
Adam

Reputation: 69

ERROR : Type 'Observable<{}[]>' is not assignable to type 'AngularFireList<any[]>'. ionic

I was trying to push data to the database but it is not going through and it is giving me errors.

This is my .ts file. In the below code this.tasks in the constructor has a red line and I don't know why.

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 
'ionic-angular';
import { AngularFireDatabase , AngularFireObject } from 
'angularfire2/database';



@IonicPage()
@Component({
selector: 'page-create-quiz',
templateUrl: 'create-quiz.html',
})
export class CreateQuizPage {
tasks : AngularFireObject <any[] > ; 

constructor(public db:AngularFireDatabase){
this.tasks = this.db.object('/tasks').valueChanges();
}



ionViewDidLoad() {
console.log('ionViewDidLoad CreateQuizPage');
}

}

This is my HTML file

<ion-header>
<ion-navbar>
<ion-title>Create you quiz here</ion-title>
</ion-navbar>
</ion-header>

<ion-content padding>
<ion-list>

<ion-item *ngFor="let task of tasks | async">

  <input type="text" [(ngModel)]="task.name">

</ion-item>

</ion-list>
</ion-content>

Upvotes: 0

Views: 50

Answers (1)

Daniel
Daniel

Reputation: 11162

Your tasks property shouldn't be typed as a AngularFireObject <any[] > ;.

Given that .valueChanges() will always return an observable, it should be typehinted as Observable<any> (like the example in the documentation)

Upvotes: 1

Related Questions