【发布时间】:2021-08-08 22:36:49
【问题描述】:
我尝试直接使用 templateDrivenForm 发布数据并从 fireBase 获取数据,但显示以下类型错误。
我的部分代码
//directly posts datas using submitButton from templateDrivenForm
onCreatePosts(postDatas:{title:string, content:string}){
this.http.post('https://ng-complete-guide-b3d7f-default-rtdb.firebaseio.com/posts.json',
postDatas)
.subscribe(
responseData => {
console.log(responseData);
});
}
//get datas from database
private fetchPost(){
return this.http.get('https://ng-complete-guide-b3d7f-default-rtdb.firebaseio.com/posts.json')
.pipe(map(responseData => {
const dataArray = [];
for(let key in responseData){
if(responseData.hasOwnProperty(key)){
dataArray.push({...responseData[key], id:key});
}
}
return dataArray;
}))
.subscribe( responseData => {
console.log(responseData)
})
}
我的错误是
Error: src/app/app.component.ts:40:28 - error TS7053: Element implicitly has an 'any' type
because
expression of type 'string' can't be used to index type 'Object'.
No index signature with a parameter of type 'string' was found on type 'Object'.
40 dataArray.push({...responseData[key], id:key});
【问题讨论】:
标签: java html css angular typescript