I can not under Stand How to Edit or Delete Get/Post API data in Ionic. I'm tried to Edit And Delete ionic Post/Get data using API. please some body help me in this ionic operation. it's argent to me. #huge_request
Asked
Active
Viewed 376 times
1 Answers
0
First in an Ionic/Angular project you'll need to import HttpClient in your TS file or service. And then use it in your function.
import { HttpClient } from '@angular/common/http';
constructor(private http: HttpClient) {}
You need to understand that you'll get a result as an Observable (https://angular.io/guide/observables). For your function to work, you'll need to subscribe to it.
Example you have a function in a service.ts file:
getData(id: string) {
return this.http.get(url, option or what the api need)
// you might need to use observable manipulation like pipe or map to get the data you want
}
In the ts file you use the service :
import {service} from 'Service'
constructor (private service: Service) {}
function() {
service.getData(id).subscribe(res => {
console.log(res)
})
}

uKioops
- 269
- 3
- 8
-
there is show a error "Property 'subcribe' does not exist on type 'void'." – Vinay Mali Jun 03 '22 at 07:42
-
sorry forgot to return it. "return this.http.get. etc" – uKioops Jun 03 '22 at 11:22