Mik*_*ke4 4 angular angular-httpclient
如何获取服务代码?我尝试下面的代码,但它没有记录任何内容。
在 service.ts 文件中。
constructor(private http: HttpClient) { }
postForgotPass(email): Observable<Response> {
return this.http.post<Response>(envi.apiUrl +'/user/forgotpassword', {
"email": email,
"headers": headers,
observe: 'response'
})
}
Run Code Online (Sandbox Code Playgroud)
在我的 component.ts 文件中
sendForgotPass() {
return this.service.postForgotPass(this.emailFormControl.value)
.subscribe(
res => {
console.log(res.status);
})
}
Run Code Online (Sandbox Code Playgroud)
来自Angular 文档:
getConfigResponse(): Observable<HttpResponse<Config>> {
return this.http.get<Config>(
this.configUrl, { observe: 'response' });
}
Run Code Online (Sandbox Code Playgroud)
用法
this.configService.getConfigResponse()
// resp is of type `HttpResponse<Config>`
.subscribe(resp => {
// display its headers
const keys = resp.headers.keys();
this.headers = keys.map(key =>
`${key}: ${resp.headers.get(key)}`);
// access the body directly, which is typed as `Config`.
this.config = { ... resp.body };
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11043 次 |
| 最近记录: |