angular - 不要从 Angular 表单发送值

标签 angular rest http webpack promise

有什么方法可以不从表单向服务器发送值吗?

我有更新请求,在此函数中我不想发送 hospital.name(我试图将其设置为 null,但它无法正常工作。)

有什么办法可以忽略这个值吗?

      update(hospital: Hospital): Promise<Hospital> {
    const url =`${this.hospitalsUrl}/${hospital.id}`;
    return this.http.put(url, JSON.stringify(hospital), {headers: this.headers})
    .toPromise()
    .then(() => hospital);
  }

最佳答案

update(hospital: Hospital): Promise<Hospital> {
delete hospital.name;
    const url =`${this.hospitalsUrl}/${hospital.id}`;
    return this.http.put(url, JSON.stringify(hospital), {headers: this.headers})
    .toPromise()
    .then(() => hospital);

delete hospital.name; 将从对象中删除属性。

var myObject = {
    "name": "muthu",
    "id": "123",
    "password": "abc-123"
};
delete myObject.password;

console.log(myObject);

关于angular - 不要从 Angular 表单发送值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49011030/

相关文章:

java - 如何在 REST Web 服务中使用 json 生成 http 响应?

html - 如何覆盖 primeng 样式?

angular - 需要任何用于 ng-sidebar 实现的运行示例

angular - 原理图 "spec": false not working on Ionic 4 app

angular - 在配置文件 'tsconfig.json' 中找不到任何输入。指定的 'include' 路径在 Angular 6 中

javascript - 通过浏览器显示范围内的蓝牙设备

java - 访问 REST Web 服务的摘要式身份验证

java - Jersey 重用子资源参数验证

java - 有没有办法在Java中 "clean"接受 header ?

http - 使用go http client Do方法时,httpResponse和error不能同时为nil吗?