When attempting to post data directly using templateDrivenForm and retrieve data from Firebase, I encountered the following type error message.
Here are the relevant parts of my code:
// Posting data directly 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);
});
}
// Retrieving data 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)
})
}
The error I am experiencing is:
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});