我正在以这种方式初始化我的表单,但是当我需要编辑它时,它不接受这些值
组件.ts
ngOnInit() {
this.tinvoiceService.initForm();
}
tinvoice.service.ts
form: FormGroup;
constructor(
private _fb: FormBuilder,
private invoiceService: InvoiceService
) {}
initForm(): void {
this.form = this._fb.group({
customer: [null, Validators.required],
totalPrice: 0,
purchases: this._fb.array([])
});
// initialize stream
const myFormValueChanges$ = this.form.controls['purchases'].valueChanges;
myFormValueChanges$.subscribe(purchases => this.updatePurchasesAmount(purchases));
}
从 HTML 我传递值
tinvoice.component.html
<a
class="btn btn-outline-info text-info"
(click)="tinvoiceService.populateForm(invoice)">
Edit
</a>
tinvoice-list.component.ts
populateForm(invoice) {
this.form.setValue(invoice);
}
通过控制台我有这个结果
有任何想法吗?