首页 > 解决方案 > 我如何从角度将本地存储值发送到服务器

问题描述

我的角度 .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 将本地存储的用户值发送到服务器

标签: angularlocal-storageangular7

解决方案


当您设置表单数据时,您可以将本地存储属性设置为与其他属性相同。

formData.append('user', localStorage.getItem('user'));

或者您可以再次调用您的服务器并单独发送。

 customizeAdd(data) {
 return this.http.post(`url`, localStorage.getItem('user'));
  }

推荐阅读