Issue
I am calling an API from my component.ts file using angular. API call is successful, however I am not able to read the data from my response.
If I print from event
, I can get the data however if I print from the this.book there is no data.
Error I am getting is error TS2339: Property 'name' does not exist on type '{}'.
component.ts
ngOnInit(): void {
this.activatedRoute.paramMap.subscribe((params: ParamMap) => {
this.id = params.get('id');
this.api.GetBook(this.id).then((event) => {
this.book = event;
console.log(event.name)// I can get response
console.log(this.book.name) //Error
});
})
Data in event or this.book is:
{__typename: 'Book', id:'1', name: "test"}
Solution
you can iterrate this.book like below.
console.log(this.book['name'])
or you have to initialize book as object type
public book = {}
Good Luck
Answered By - Saurabh Gupta
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.