Angular 角度HttpClient类型检查Post请求';雷普森斯酒店
对于Angular(4.3+)中的新HttpClient,是否也可以使用POST类型检查(以及其他请求的类型)?官方文档()仅提到GET请求:Angular 角度HttpClient类型检查Post请求';雷普森斯酒店,angular,angular-httpclient,Angular,Angular Httpclient,对于Angular(4.3+)中的新HttpClient,是否也可以使用POST类型检查(以及其他请求的类型)?官方文档()仅提到GET请求: interface ItemsResponse { results: string[]; } ... http.get<ItemsResponse>('/api/items').subscribe(data => { // data is now an instance of type ItemsResponse, so
interface ItemsResponse {
results: string[];
}
...
http.get<ItemsResponse>('/api/items').subscribe(data => {
// data is now an instance of type ItemsResponse, so you can do this:
this.results = data.results;
});
接口项响应{
结果:字符串[];
}
...
http.get('/api/items').subscribe(数据=>{
//data现在是ItemsResponse类型的实例,因此您可以执行以下操作:
this.results=data.results;
});
它对其他类型的请求是否也同样有效?据我所知,它确实有效。比如说
interface LoginResponse {
token: string;
}
...
this.http.post<LoginResponse>(url, body, options).subscribe(
data => {
this.jwtoken = data.token;
return 'Login successful';
},
err => {
console.log(err);
}
);
接口登录响应{
令牌:字符串;
}
...
this.http.post(url、正文、选项)。订阅(
数据=>{
this.jwtoken=data.token;
返回“登录成功”;
},
错误=>{
控制台日志(err);
}
);
据我所知,确实如此。比如说
interface LoginResponse {
token: string;
}
...
this.http.post<LoginResponse>(url, body, options).subscribe(
data => {
this.jwtoken = data.token;
return 'Login successful';
},
err => {
console.log(err);
}
);
接口登录响应{
令牌:字符串;
}
...
this.http.post(url、正文、选项)。订阅(
数据=>{
this.jwtoken=data.token;
返回“登录成功”;
},
错误=>{
控制台日志(err);
}
);