app/app.module.ts
// ● Add this
import { HttpClientModule } from '@angular/common/http';
imports: [
BrowserModule,
HttpClientModule, // ● Add this
..... ,
..... ,
例 (app/posts/posts.page.ts)
app/posts/posts.page.ts
// ● Add this
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
....
....
// ● Add this
constructor(private http: HttpClient) { }
// ● Add this
ngOnInit(): void {
// Make the HTTP request:
this.http.get('https://YOUR-SERVER.TLD/api/posts').subscribe(data => {
console.log(data);
console.log(data[1]['name']);
});
}