使用ionic 3中的changes.map从firebase获取数据时出错
我试图根据登录用户ID从firebase获取数据,但在使用changes.map时出错。vscode中显示的错误是“类型“未知”上不存在属性“映射” 以下是我获取数据的方式: -----------------shopping-list.ts:-----------------使用ionic 3中的changes.map从firebase获取数据时出错,firebase,firebase-realtime-database,ionic3,Firebase,Firebase Realtime Database,Ionic3,我试图根据登录用户ID从firebase获取数据,但在使用changes.map时出错。vscode中显示的错误是“类型“未知”上不存在属性“映射” 以下是我获取数据的方式: -----------------shopping-list.ts:----------------- shoppingList$: Observable<Item[]>; userId: string; profileData: Observable<Profile>; constr
shoppingList$: Observable<Item[]>;
userId: string;
profileData: Observable<Profile>;
constructor(public navCtrl: NavController, private shopping: shoppingListService,
public db: AngularFireDatabase, private toast: ToastService,
private afAuth: AngularFireAuth, private account: userAccountService) {}
ionViewWillLoad(){
this.afAuth.authState.subscribe(data => {
if(data && data.email && data.uid){
this.profileData = this.db.object<Profile>(`profile/${data.uid}`).valueChanges();
this.userId = data.uid;
this.getItemList();
}
else{
this.navCtrl.setRoot('LoginPage');
}
})
}
getItemList(){
try{
this.shoppingList$ = this.shopping
.getShoppingList() //this reruns the DB list
.snapshotChanges() //this gives the keys and value pairs
.pipe(map(
changes => {
**return changes.map(c => ({//this changes.map is where the error is showing**
key: c.payload.key,
...c.payload.val()
}));
}
));
}
catch(e){
console.error(e);
}
}
此错误是在我使用npm i将typescript升级到最新版本后开始的typscript@latest并将其更新为版本“^3.9.7”
-----我尝试过的事情-------
- 降低打字脚本的级别
- 将rxjs和rxjs compat升级到6.5.5,6.3.0,6.2.0
- 创建了一个新项目
- 删除节点_模块、package-lock.jason和npm安装了吗
我真的需要帮助,因为我已经在这几天没有解决办法。多亏了你们大家,我找到了解决问题的办法。 我给shoppingListRef分配了一个类型any,而不是AngularFireList 最初是:
private shoppingListRef: any;
更新至:
import { AngularFireDatabase, AngularFireList } from "angularfire2/database";
private shoppingListRef: AngularFireList<Item>;
从“angularfire2/数据库”导入{AngularFireDatabase,AngularFireList};
私人shoppingListRef:AngularFireList;
上述更改解决了问题我找到了问题的解决方案。 我给shoppingListRef分配了一个类型any,而不是AngularFireList 最初是:
private shoppingListRef: any;
更新至:
import { AngularFireDatabase, AngularFireList } from "angularfire2/database";
private shoppingListRef: AngularFireList<Item>;
从“angularfire2/数据库”导入{AngularFireDatabase,AngularFireList};
私人shoppingListRef:AngularFireList;
上述改变解决了这个问题
import { AngularFireDatabase, AngularFireList } from "angularfire2/database";
private shoppingListRef: AngularFireList<Item>;