1. ng add ng-zorro-antd 安装这个就是直接导入了,不需要我们再次的引入

1 app.module.ts配置

  1. import {HttpClientModule} from '@angular/common/http'
  2. imports: [
  3. ...
  4. HttpClientModule,
  5. ],

2 在发送http请求的组件中配置

  1. import {HttpClient} from '@angular/common/http'
  2. export class ContentComponent implements OnInit {
  3. public programs:any;
  4. constructor(public http:HttpClient) { }
  5. ngOnInit() {
  6. var url:string="http://192.168.14.15:5000/dj/program?rid=336355127"
  7. this.http.get(url).subscribe(res=>{
  8. console.log(res['programs'])
  9. this.programs=res['programs']
  10. })
  11. }
  12. tips:ngOnInit() {} //相当于onLoad(),mounted()生命周期