1. //app.module.ts中去注册
    2. import {HttpClientModule} from '@angular/common/http' //注册http请求
    3. @NgModule({
    4. ...
    5. imports: [
    6. BrowserModule,
    7. HttpClientModule
    8. ]
    9. ...
    10. })
    1. //app.component.ts配置
    2. import {HttpClient} from '@angular/common/http' //配置http请求
    3. export class AppComponent {
    4. constructor(public http:HttpClient){}
    5. ngOnInit(){
    6. var url:string = "http://localhost:8000/top250";
    7. this.http.get(url).subscribe(res=>{
    8. console.log(res)
    9. })
    10. }
    11. }