I'm learning the ionic framework and want to know how REST calls are done correctly.
I have a RestProvider class which gets me a list of products
rest.ts
getProduct(query: string) {
return this.http.get(searchUri+query)
}
And in my home page I want to assign a value from the response to a local variable
home.ts
ionViewDidLoad() {
this.restProvider.getProduct(query).subscribe(it => {
console.log(it)
this.products = it.result;
})
}
But I get an error on assignment line this.products = it.result;
[ts] Property result does not exist on type Object
How do I create models of my response and assign them to class variables?
this.http.get<any>(searchUri+query)and it should work. Better yet, if you have an interface that represents the response, use that instead ofany