>app.module.ts中 引入模块 ~~~ import {HttpClientModule} from "@angular/common/http"; ~~~ >同理注 依赖注入 模块 ~~~ imports: [ BrowserModule, HttpClientModule, FormsModule, AppRoutingModule ], ~~~ >在要使用的地方 httpclient.component.ts 中引入模块 ~~~ import {HttpClient,HttpHeaders} from "@angular/common/http"; ~~~ >构造函数初始化中依赖注入 ~~~ export class HttpclientComponent implements OnInit { constructor(public httpclient:HttpClient) { } } ~~~ >具体使用 ~~~ public rxjsHttp(){ let api='http://www.mxact.com/v1/gateway/core/commonweal/tencent_gj_url'; //rxjs this.httpclient.get(api).subscribe(response=>{ console.log(response); }) } public rxjsPost(){ //header头 const httpOptions={ headers:new HttpHeaders({"asadasd":"enaaa"}) } let api='http://www.mxact.com/v1/gateway/core/commonweal/tencent_gj_url'; //rxjs this.httpclient.post(api,{url:"http://www.baidu.com"},httpOptions).subscribe(response=>{ console.log(response); }) } ~~~