Angular 5 反应形式 主键

Angular 5 reactive forms Primary key

你如何处理对象唯一ID/主键? 你将它添加到 FormGroup 中吗?

 this.user = this.fb.group({
  id: [''],
  name: ['', Validators.required ]
});

我能想到两种可能的方法。

一个

Have this value as an input field with a hidden attribute so that you can use it to edit or save during submit

第二

The other way is as you are making use of Reactive Forms you need not have it as an hidden field as you know with reactive Forms you have data as part of NgForm when anything changes . What you can do is create a dummy Submit button for the same and at the time of submit have all the data of form and append the data from the api for the id and then pass it to the service . Only down side is you cannot use native form submit