学习post请求之前,必须先学习一下Get请求,重点完成Get请求中的http服务。
①在.page.ts界面引入并声明公共服务
import { HttpHeaders,HttpClient } from '@angular/common/http';
constructor(
public http:HttpClient,
) {}
②具体的方法使用
//提交建议的方法——冯佳兴—2019年4月24日09:30:19
submitClick() {
this.feedBackModel.companyId='23VAJAVAXT492QKFsfUBru' //localStorage.getItem('companyId');
this.feedBackModel.projectId="H5Xhdnx4SxRiPBeEYixYjw"
this.feedBackModel.suggestion=this.person.actives;
this.feedBackModel.userId=window.localStorage.getItem('UserNameOnlyLastThreeNum');
const httpOptions = {
headers:new HttpHeaders({'Content-Type':'application/json'})//请求头进行转格式,防止出现415错误
};
const body=JSON.stringify(this.feedBackModel);
const url='http://192.168.22.119:8090/tool-web/suggestion/commitSuggestion';
this.http.post(url,body,httpOptions).subscribe(res=>{
if(res){
this.presentAlertMultipleButtons();
}
else{
this.presentAlert();
}
});
}
Ionic4中Get请求的学习与实现
博客主要围绕Ionic4中的Get请求展开,指出在学习post请求前需先掌握Get请求,重点是完成Get请求中的http服务,还介绍了在.page.ts界面引入并声明公共服务以及具体的方法使用。
215

被折叠的 条评论
为什么被折叠?



