A.app.module.ts
    导入
    image.png
    配置
    image.png
    B.app.component.ts

    1. ...
    2. import{HttpClient} from '@angular/common/http'
    3. ...
    4. export class AppComponent {
    5. title = 'my-app';
    6. //在构造函数中注册
    7. constructor(public http:HttpClient){}
    8. //组件初始化触发
    9. ngOnInit(){
    10. var url:string="http://localhost:8000/top250";
    11. this.http.get(url).subscribe(res=>{
    12. console.log(res);
    13. })
    14. }
    15. }

    image.png