一、app.module.ts配置
import {HttpClientModule} from '@angular/common/http'
imports: [
BrowserModule,
HttpClientModule
],
二、在发送http请求的组件中配置HttpClient,作为构造函数的参数设置
import { Component, OnInit } from '@angular/core';
import {HttpClient} from '@angular/common/http'
@Component({
selector: 'app-content',
templateUrl: './content.component.html',
styleUrls: ['./content.component.scss']
})
export class ContentComponent implements OnInit {
public musics:any []
constructor(public http:HttpClient) { }
ngOnInit() {
var url:string = "http://192.168.14.15:5000/dj/program?rid=336355127"
this.http.get(url).subscribe(res=>{
this.musics = res["programs"]
})
}
}