angular - 如何获取已创建记录的 ID?
问题描述
我想获取hour_id
已创建记录的 id ()。我需要为此做些什么?添加hour_id
到表格?或者是其他东西?
this.form = new FormGroup({
teams_id: new FormControl(null, [Validators.required]),
team_name: new FormControl({ value: "", disabled: true }, Validators.required),
well: new FormControl(null, [Validators.required]),
layer: new FormControl(null),
chock: new FormControl(null)
})
onSave() {
this._service.create(this.form.value).subscribe(
() => {
this._toast.success("Saved.");
// console.log(this.form.controls.hour_id) ?
},
error => {
this._toast.error(error.error.message);
}
)
}
解决方案
您需要添加一个与您将从服务器返回的名称相同的新表单控件。假设您要返回 value hour_id
,请将 hour_id 添加到表单中。
this.form = new FormGroup({
hour_id: new FormControl(null),
teams_id: new FormControl(null, [Validators.required]),
team_name: new FormControl({ value: "", disabled: true }, Validators.required),
well: new FormControl(null, [Validators.required]),
layer: new FormControl(null),
chock: new FormControl(null)
})
onSave() {
this._service.create(this.form.value).subscribe(
() => {
this._toast.success("Saved.");
console.log(this.form.controls.hour_id.value) ?
},
error => {
this._toast.error(error.error.message);
}
)
}
当您使用返回的响应将值修补到表单时,hour_id
将会更新。
推荐阅读
- django - Django:当我尝试从我的数据库中删除一个对象时,为什么我得到 404?
- java - 序列化与 toString()
- conv-neural-network - cnn提取特征使用svm图像分类的问题
- kubernetes - 来自 pod 的 curl 成功,但 restTemplate 调用在 Spring Boot 应用程序中提供连接 TimeOut
- android - 如何以与kotlin中的firebase数据库相同的顺序保存大型arrayList?
- python - opencv 由 cmake 和 cuda 构建,一个构建 python 工作,但 c++ 没有
- node.js - 无服务器:层没有文件匹配包含/排除模式
- remote-desktop - 如何为客户端正确映射 Windows Server RDS 环境中的打印机?
- vue.js - 为什么在 vue.js 项目中安装惯性.js 时出现“安装对等依赖项”错误?
- javascript - 如何使用固定数量的矩形找出大小(矩形必须是)以将所有矩形放入画布内?