...
import { HttpClientModule } from '@angular/common/http';
...
imports: [
...
HttpClientModule
],
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');
}
}
...
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