1. Here is the code, you need to add into your app.module.ts file:

...
import { HttpClientModule } from '@angular/common/http';
...
 imports: [
    ...
  HttpClientModule
  ],

2. Now you need to create new file app/app.service.ts and add below code inside it:

import { Injectable } from '@angular/core'; 
import { HttpClient } from '@angular/common/http';
@Injectable()
export class appService { 
constructor(private http:HttpClient) { }
public getPosts()
    {
        return this.http.get('http://localhost/mypage.php');
    }
}

3. Now you need to add below code into app.component.ts file:

...
import { appService } from './app.service'; 
@Component({
  ...
  providers: [appService]
})
export class AppComponent {
  ...
  data = [];
  constructor(private appservice: appService) {} 
  ngOnInit() {

  this.appservice.getPosts().subscribe((ret: any[])=>{
      console.log(ret);
      this.data = ret;
    })
  }
}

#angular 8 #angular 9 #mysql #php

Angular 9 services working example with php mysql
22.70 GEEK