angular - Angular HttpClient 不发送 gettter 提供的属性
问题描述
学生.ts
...
private _status: string;
...
get status() {
return this._status;
}
...
学生服务.ts
...
save(student: Student): Observable<Student> {
const postStudentURL = 'http://localhost:8080/api/students';
return this.httpClient.post<Student>(postStudentURL, student);
}
...
JSON 发送到后端
{
...
"_status": "Valid",
...
}
为什么不发送状态,而是发送私有 _status ?
解决方案
return this.httpClient.post<Student>(postStudentURL, student);
上面的行发送json
学生对象的表示。
所以请求包含字段而不是getter。
为了确认,您可以手动创建一个实例,Student
然后console.log(JSON.stringify(student))
推荐阅读
- wordpress - 制作默认保护的 Wordpress 帖子/页面密码
- android - Flutter 应用程序,ListView.builder 首次运行时出现错误。需要重启应用(ListView.builder 和 image_picker)
- node.js - JavaScript 的异步属性导致错误
- python - AnticaptchaException: [ERROR_KEY_DOES_NOT_EXIST:1] 在系统中找不到帐户授权密钥
- javascript - 当我使用新路径()关闭它们时,画布路径连接
- c++ - 内部类从全局变量访问父级
- reactjs - 如何解决 Storybook 中的别名?
- java - 我不知道为什么这个方法被调用了两次
- java - 列出设备外部存储上的目录内容 (Kotlin)
- workflow - 用于多个传感器的节点红色动态 RBE