一、引用
//app.module.ts
import {HttpClientModule} from '@angular/common/http'
二、注册
//app.module.ts
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule
],
三、在组件中使用http
1.先引用
例如在content组件中使用
//content.component.ts
import{HttpClient} from '@angular/common/http'
2.注册
constructor(public http:HttpClient) {
}
3.使用
ngOnInit() {
var url:string="https://music.aityp.com/top/playlist?cat=日语"
this.http.get(url).subscribe(res=>{
console.log(res)
})
}