AngularFIRE Property 'subscribe' does not exist on type 'AngularFireList<{}>'

后端 未结 5 1636
名媛妹妹
名媛妹妹 2021-02-06 03:18

I\'m following this tutorial about how to connect angular with firebase database. But in minute 17:30 I\'m getting this error:

Property \'subscribe\' does not ex

相关标签:
5条回答
  • 2021-02-06 03:38

    Starting in AngularFire 5.0 you'll want to use one of snapshotChanges(), valueChanges<T>(), stateChanges(), or auditTrail(). See the 5.0 migration guide.

    Get started with the most basic, valueChanges():

    export class AppComponent {
      countries: Observable<Country[]>;
      constructor(db: AngularFireDatabase ) {
        this.countries = db.list('/Country/countries').valueChanges();
      }
    }
    
    0 讨论(0)
  • 2021-02-06 03:50

    Try the next:

    export class AppComponent {
      countries: any[];
    
      constructor(db: AngularFireDatabase )
      {
          this.countries = db.list('/Country/countries').valuesChanges();
      }
    }
    

    And if you have a model then:

    export class AppComponent {
      countries: Country[];
    
      constructor(db: AngularFireDatabase )
      {
         this.countries = db.list<Country>('/Country/countries').valueChanges();
      }
    }
    
    0 讨论(0)
  • 2021-02-06 03:59

    A simpler change would to be add valueChanges() before .subscribe()

    db.list('/Country/countries').valueChanges().subscribe(countries => {
        this.countries = countries;
        console.log(this.countries);
    });
    
    0 讨论(0)
  • 2021-02-06 03:59

    export class AppComponent { constructor(db : AngularFireDatabase) { db.list('/courses').valueChanges().subscribe()

    } }

    In Angular firebase version 5.0 and above .subscribe is available after .valuechanges()

    0 讨论(0)
  • 2021-02-06 04:01
    import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';
    import { Observable } from 'rxjs';
    

    Import code the code,

     countries: Observable<any[]>;
     allCountries: any;
    
      constructor(db: AngularFireDatabase ) {
        this.countries = db.list('/yourpath').valueChanges();  
        this.countries.subscribe(countries => {
          this.allCountries = countries;
          console.log(this.allCountries);
        })
        console.log(this.countries)
      }
    
    0 讨论(0)
提交回复
热议问题