Angular配置http请求
文章目录
- 在app.module.ts中引入我们http请求模块:
// 引入angular的内置请求模块
import {HttpClientModule} from '@angular/common/http'- 在app.module.ts的模块配置中,配置我们引入的http请求模块:
// 配置模块
imports: [
BrowserModule,
// 请求模块
HttpClientModule
]- 如果只是单单使用get请求
// 在组件中引入http请求服务---get请求
import {HttpClient} from '@angular/common/http'- 如果还要用post请求的话,还需要引入httpHeaders
// 如果是post请求,还需要引入httpHeaders
import {HttpClient,HttpHeaders} from '@angular/common/http'然后在我们组件的ts文件的constructor构造器中声明一下即可
// 声明
constructor(public http:HttpClient) { }
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论