Issue
so i have been following this tutorial https://devdactic.com/sqlite-ionic-app-with-capacitor/ but I got an error in home.page.ts for this.products= res.values; it said Property 'values' does not exist on type 'unknown'. not sure what does it mean and how to solve it, i am totally beginner in ionic and hope anyone can help me to explain and help me with this.
Solution
It's an error from typescript. By default in angular tsconfig.json
it has a configuration noImplicityAny
. That means, you have to specify types, otherwise typescript will yell at you
Quick Fix (not-recommendable)
this.databaseService.getProductList().subscribe((res: any) => {
this.products = res.values;
});
Recommended Fix
Service
interface Product {
...
}
interface ProductResponse {
values: Product[];
}
getProductList() {
return this.http.get<ProductResponse>('https://url/to/api');
}
// HomePage
products: Product[] = [];
this.databaseService.getProductList().subscribe((res) => {
this.products = res.values;
});
Answered By - Pankaj Parkar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.