本文介绍了AngularFIRE 属性“订阅"在类型“AngularFireList<{}>"上不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在关注本教程,了解如何将 angular 与 firebase 数据库连接.但在 17:30 分钟,我收到此错误:
I'm following this tutorial about how to connect angular with firebase database. But in minute 17:30 I'm getting this error:
属性订阅"不存在于类型AngularFireList"
我的应用组件:
import { Component } from '@angular/core';
import {AngularFireDatabase, AngularFireDatabaseModule} from 'angularfire2/database';
import {AngularFireAuth, AngularFireAuthModule} from 'angularfire2/auth';
import { Observable } from 'rxjs/Observable';
import * as firebase from 'firebase/app';
import { Country } from './models/country';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
countries: any[];
constructor(db: AngularFireDatabase )
{
db.list('/Country/countries')
.subscribe(countries => { // <--ERROR IS HERE
this.countries = countries;
console.log(this.countries);
});
}
}
我的模型:
export class Country {
// --ATTRIB--
id: string;
name: string;
code: string;
urlFlag: string;
}
无法找到有关此错误的任何信息.我是角度的初学者.如果可以帮助我,谢谢.
Cant find anything about this error. I'm beginner in angular. Thanks if can help me.
推荐答案
从 AngularFire 5.0 开始,您将需要使用 snapshotChanges()
、valueChanges<T>()、
stateChanges()
或 auditTrail()
.请参阅 5.0 迁移指南.
Starting in AngularFire 5.0 you'll want to use one of snapshotChanges()
, valueChanges<T>()
, stateChanges()
, or auditTrail()
. See the 5.0 migration guide.
从最基本的开始,valueChanges()
:
export class AppComponent {
countries: Observable<Country[]>;
constructor(db: AngularFireDatabase ) {
this.countries = db.list('/Country/countries').valueChanges();
}
}
这篇关于AngularFIRE 属性“订阅"在类型“AngularFireList<{}>"上不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!