angular - 我如何从角度将本地存储值发送到服务器
问题描述
我的角度 .ts 文件是
const clothsize = this.sizeForm.value.clothsize;
const quantity = this.sizeForm.value.quantity;
var formData = new FormData();
formData.append('image', file);
formData.append('clothsize', clothsize);
formData.append('quantity', quantity);
formData.append('design', this.fileDesign);
this.service.customizeAdd(formData)
}
service.ts 文件是
customizeAdd(data) {
return this.http.post(`${this.baseURL}/file`, data);
}
我想将不同模块的本地存储值添加到我已将本地存储值设置为的特定表单数据中
localStorage.setItem('user', customeruser.payload.mobilenumber);
我在本地存储中具有价值
user : 3456788922
我正在尝试使用上面的 formdata 将本地存储的用户值发送到服务器
解决方案
当您设置表单数据时,您可以将本地存储属性设置为与其他属性相同。
formData.append('user', localStorage.getItem('user'));
或者您可以再次调用您的服务器并单独发送。
customizeAdd(data) {
return this.http.post(`url`, localStorage.getItem('user'));
}
推荐阅读
- angularjs - ng-table-dynamic 中基于日期的排序
- ceph - 命令超时 [osd1][INFO] 运行命令:sudo /usr/sbin/ceph-volume
- java - Android Studio 项目中库的导入类被锁定
- r - 可能的错误:在 Ubuntu 18.04 LTS 上使用 nlme 时 R CMD 检查失败
- android - 当前活动在计时器结束前自动启动?
- r - 从 R 中的 big.matrix 创建图表
- angular - 自 Angular CLI 6 以来,ng build --prod 不会缩小/丑化/删除评论
- ethereum - Web3.js 不使用 geth 节点返还帐户
- sapui5 - 主从模板中的主视图绑定到拆分应用程序的母版页的位置在哪里?
- sql - 使用 Oracle 过滤 2 个字段的数据