【发布时间】:2017-11-06 18:16:33
【问题描述】:
我正在尝试在我的 ionic2 应用程序中更新 firebase 中的数据,但出现此错误:
cannot read property '$key' of undefined
.ts
onValidate(info): void{
//console.log(info.$key);
this.infos.update(info.$key,{
FirstName : info.FirstName,
LastName : info.LastName
})
}
.html
<button
ion-button
type="submit"
block
[disabled]="!f.valid"
(click)="onValidate(info)">Valider</button>
在我的 html 中,我有一个 *ngFor = "let info of infos | async" ...
感谢您的帮助
【问题讨论】:
-
您的问题中没有足够的代码来确定。据推测,
infos是Promise或Observable正在解析或推送undefined -
infos是infos: FirebaseListObservable<any>,您需要其他信息吗? @Aluan Haddad -
是的,
undefined可分配给any。在这种情况下使用any基本上可以抑制由于错误的映射调用(缺少返回或括号)、意外地将 void 函数映射到可观察对象以及大量其他错误而导致的任何可能的类型错误。不要使用any,除非在极少数情况下逗号不是其中之一,因为您显然有对象的预期形状。无论如何,调试它的最简单方法是订阅您的视图模型中的可观察对象并简单地记录每个值 -
感谢@AluanHaddad。我不明白如何记录每个值?
-
设置
this.infos = whatever;后在视图模型(.ts文件)中添加this.infos.subscribe(console.log)
标签: angular firebase firebase-realtime-database ionic2