一、app.module.ts配置

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

二、在发送http请求的组件中配置HttpClient,作为构造函数的参数设置

  1. import { Component, OnInit } from '@angular/core';
  2. import {HttpClient} from '@angular/common/http'
  3. @Component({
  4. selector: 'app-content',
  5. templateUrl: './content.component.html',
  6. styleUrls: ['./content.component.scss']
  7. })
  8. export class ContentComponent implements OnInit {
  9. public musics:any []
  10. constructor(public http:HttpClient) { }
  11. ngOnInit() {
  12. var url:string = "http://192.168.14.15:5000/dj/program?rid=336355127"
  13. this.http.get(url).subscribe(res=>{
  14. this.musics = res["programs"]
  15. })
  16. }
  17. }